程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> SQLServer服務器訪問ADO

SQLServer服務器訪問ADO

編輯:關於SqlServer
平常我們只聽說過ADO等一類ASP對象,但在ASP中還有個鮮為人知的專門SQL Server的ASP訪問對象,它就是SQLOLE.SQLServer對象。SQLOLE.SQLServer可以直接訪問SQL Server的系統屬性。以Set oSQLServer = CreateObject ("SQLOLE.SQLServer")語句將產生一個SQL Server服務器對象。
  
  若要查看此服務器中數據庫的集合,可用語句:
  For Each SQLDB In oSQLServer.Databases
  Response.Write SQLDB.Name ‘將列出所有的數據庫,如Pubs等
  Next
  
  若要查看某數據庫中(如PUBS數據庫)數據表的集合,可用語句:
  
  pubDatabase=oSQLServer.Databases(“pubs”)
  ’oSQLServer是前面創建的SQL Server服務器對象
  For Each DBTable In pubDatabase.Tables
  Response.Write DBTable.Name
  Next
  
  下面的語句將列出數據庫中(PUBS數據庫)數據視圖
  
  pubDatabase =oSQLServer.Databases(“pubs”)
  ’oSQLServer是前面創建的SQL Server服務器對象
  For Each DBView In pubDatabase.VIEws
  Response.Write DBVIEw.Text
  Next
  
  以下語句將列出數據庫中(PUBS數據庫)存貯過程
  
  pubDatabase =oSQLServer.Databases(“pubs”)
  ’oSQLServer是前面創建的SQL Server服務器對象
  For Each DBSP In pubDatabase.StoredProcedures
  Response.Write DBSP.Text
  Next
  
  程序運行的結果(取數據表名):
  
  取存貯過程的結果:
  一個完整的小例子源碼附後(其它功能讀者可加入)。
  
  < %@ LANGUAGE = VBScript % >
  
  < Html >
  < HEAD >
  < META NAME="GENERATOR" Content=
  "Microsoft Developer Studio" >
  < META HTTP-EQUIV="Content-Type"
  content="text/Html; charset=gb2312" >
  
  < TITLE >< /TITLE >
  < /HEAD >
  
  < %
  On Error Resume Next
  Dim oSQLServer
  Set oSQLServer = CreateObject ("SQLOLE.SQLServer")
  
  strServer = "dep"
  strLogin = "sa"
  strPwd = ""
  
  oSQLServer.Connect strServer,strLogin,strPwd
  
  % >
  
  < BODY BGCOLOR=#ffffff >
  數據庫列表
  < SELECT NAME="Database" >
  < %
  For Each SQLDB In oSQLServer.Databases
  If Not SQLDB.SystemObject Then
  Response.Write "< OPTION VALUE=
  """ & SQLDB.Name & """ >" & SQLDB.Name
  
  & " "
  End If
  Next
  Set oSQLServer = Nothing
  % >
  < /SELECT >
  < /BODY >
  < /Html >
  
  平常我們只聽說過ADO等一類ASP對象,但在ASP中還有個鮮為人知的專門SQL Server的ASP訪問對象,它就是SQLOLE.SQLServer對象。SQLOLE.SQLServer可以直接訪問SQL Server的系統屬性。

以Set oSQLServer = CreateObject ("SQLOLE.SQLServer")語句將產生一個SQL Server服務器對象。
  
  若要查看此服務器中數據庫的集合,可用語句:
  
  For Each SQLDB In oSQLServer.Databases
  Response.Write SQLDB.Name ‘將列出所有的數據庫,如Pubs等
  Next
  
  若要查看某數據庫中(如PUBS數據庫)數據表的集合,可用語句:
  
  pubDatabase=oSQLServer.Databases(“pubs”)
  ’oSQLServer是前面創建的SQL Server服務器對象
  For Each DBTable In pubDatabase.Tables
  Response.Write DBTable.Name
  Next
  
  下面的語句將列出數據庫中(PUBS數據庫)數據視圖
  
  pubDatabase =oSQLServer.Databases(“pubs”)
  ’oSQLServer是前面創建的SQL Server服務器對象
  For Each DBView In pubDatabase.VIEws
  Response.Write DBVIEw.Text
  Next
  
  以下語句將列出數據庫中(PUBS數據庫)存貯過程
  
  pubDatabase =oSQLServer.Databases(“pubs”)
  ’oSQLServer是前面創建的SQL Server服務器對象
  For Each DBSP In pubDatabase.StoredProcedures
  Response.Write DBSP.Text
  Next
  
  程序運行的結果(取數據表名):
  
  取存貯過程的結果:
  一個完整的小例子源碼附後(其它功能讀者可加入)。
  
  < %@ LANGUAGE = VBScript % >
  
  < Html >
  < HEAD >
  < META NAME="GENERATOR" Content=
  "Microsoft Developer Studio" >
  < META HTTP-EQUIV="Content-Type"
  content="text/Html; charset=gb2312" >
  
  < TITLE >< /TITLE >
  < /HEAD >
  
  < %
  On Error Resume Next
  Dim oSQLServer
  Set oSQLServer = CreateObject ("SQLOLE.SQLServer")
  
  strServer = "dep"
  strLogin = "sa"
  strPwd = ""
  
  oSQLServer.Connect strServer,strLogin,strPwd
  
  % >
  
  < BODY BGCOLOR=#ffffff


您正在看的SQLserver教程是:SQLServer服務器訪問ADO。>
  數據庫列表
  < SELECT NAME="Database" >
  < %
  For Each SQLDB In oSQLServer.Databases
  If Not SQLDB.SystemObject Then
  Response.Write "< OPTION VALUE=
  """ & SQLDB.Name & """ >" & SQLDB.Name
  
  & " "
  End If
  Next
  Set oSQLServer = Nothing
  % >
  < /SELECT >
  < /BODY >
  < /Html >
  
  列出 IE5 所支持的所有server端變量
  
  以下是MSDN (1999年4月版)提供的 IE5 所支持的所有server端變量
  部分變量在以前的版本中不支持,而且在以後的版本中可能會有變化(這是Microsoft的原話)
  
  Variable Description
  ALL_HTTP All HTTP headers sent by the clIEnt.
  ALL_RAW Retrieves all headers in the raw-form. The difference between ALL_RAW and ALL_HTTP is that ALL_HTTP places an HTTP_ prefix before the header name and the header-name is always capitalized. In ALL_RAW the header name and values appear as they are sent by the clIEnt.
  APPL_MD_PATH RetrIEves the metabase path for the (WAM) Application for the ISAPI DLL.
  APPL_PHYSICAL_PATH RetrIEves the physical path corresponding to the metabase path. IIS converts the APPL_MD_PATH to the physical (directory) path to return this value.
  AUTH_PASSWord The value entered in the clIEnt's authentication dialog. This variable is only available if Basic authentication is used.
  AUTH_TYPE The authentication method that the server uses to validate users when they attempt to Access a protected script.
  AUTH_USER Raw authenticated user name.
  CERT_COOKIE Unique ID for client certificate, Returned as a string. Can be used as a signature for the whole clIEnt certificate.
  CERT_FLAGS bit0 is set to 1 if the clIEnt certificate is present.
  bit1 is set to 1 if the Certificate Authority of the clIEnt certificate is invalid (not in the list of recognized CA on the server).
  
  CERT_ISSUER Issuer field of the clIEnt certificate (O=MS, OU=IAS, CN=user name, C=USA).
  CERT_KEYSIZE Number of bits in Secure Sockets Layer connection key size. For example, 128.
  CERT_SECRETKEYSIZE Number of bits in server certificate private key. For example, e.g. 1024.
  CERT_SERIALNUMBER Serial number field of the clIEnt certificate.
  CERT_SERVER_ISSUER Issuer fIEld of the server certificate.
  CERT_SERVER_SUBJECT Subject fIEld of the server certificate.
  CERT_SUBJECT Subject field of the clIEnt certificate.
  CONTENT_LENGTH The length of the content as given by the clIEnt.
  CONTENT_TYPE The data type of the content. Used with queries that have attached information, such as the HTTP querIEs GET, POST, and PUT.
  GATEWAY_INTERFACE The revision of the CGI specification used by the server. The format is CGI/revision.
  HTTP_ The value stored in the header HeaderName. Any header other than those listed in this table must be prefixed by HTTP_ in order for the ServerVariables collection to retrIEve its value.
  Note The server interprets any underscore (_) characters in HeaderName as dashes in the actual header. For example if you specify HTTP_MY_HEADER, the server searches for a header sent as MY-HEADER.
  
  HTTP_ACCEPT Returns the value of the Accept header.
  HTTP_ACCEPT_LANGUAGE Returns a string describing the language to use for displaying content.
  HTTP_USER_AGENT Returns a string describing the browser that sent the
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved