ASP訪問(wèn)SQL Server內(nèi)置對(duì)象 發(fā)表時(shí)間:2023-08-13 來(lái)源:明輝站整理 相關(guān)軟件 相關(guān)文章 人氣:
[摘要] 平常我們只聽說(shuō)過(guò)ADO等一類ASP對(duì)象,但在ASP中還有個(gè)鮮為人知的專門SQL Server的ASP訪問(wèn)對(duì)象,它就是SQLOLE.SQLServer對(duì)象。SQLOLE.SQLServer可以直接訪問(wèn)...
平常我們只聽說(shuō)過(guò)ADO等一類ASP對(duì)象,但在ASP中還有個(gè)鮮為人知的專門SQL Server的ASP訪問(wèn)對(duì)象,它就是SQLOLE.SQLServer對(duì)象。SQLOLE.SQLServer可以直接訪問(wèn)SQL Server的系統(tǒng)屬性。以Set oSQLServer = CreateObject ("SQLOLE.SQLServer")語(yǔ)句將產(chǎn)生一個(gè)SQL Server服務(wù)器對(duì)象。 ---- 若要查看此服務(wù)器中數(shù)據(jù)庫(kù)的集合,可用語(yǔ)句:
For Each SQLDB In oSQLServer.Databases Response.Write SQLDB.Name ‘將列出所有的數(shù)據(jù)庫(kù),如Pubs等 Next
---- 若要查看某數(shù)據(jù)庫(kù)中(如PUBS數(shù)據(jù)庫(kù))數(shù)據(jù)表的集合,可用語(yǔ)句:
pubDatabase=oSQLServer.Databases(“pubs”) ’oSQLServer是前面創(chuàng)建的SQL Server服務(wù)器對(duì)象 For Each DBTable In pubDatabase.Tables Response.Write DBTable.Name Next
---- 下面的語(yǔ)句將列出數(shù)據(jù)庫(kù)中(PUBS數(shù)據(jù)庫(kù))數(shù)據(jù)視圖
pubDatabase =oSQLServer.Databases(“pubs”) ’oSQLServer是前面創(chuàng)建的SQL Server服務(wù)器對(duì)象 For Each DBView In pubDatabase.Views Response.Write DBView.Text Next
---- 以下語(yǔ)句將列出數(shù)據(jù)庫(kù)中(PUBS數(shù)據(jù)庫(kù))存貯過(guò)程
pubDatabase =oSQLServer.Databases(“pubs”) ’oSQLServer是前面創(chuàng)建的SQL Server服務(wù)器對(duì)象 For Each DBSP In pubDatabase.StoredProcedures Response.Write DBSP.Text Next
---- 程序運(yùn)行的結(jié)果(取數(shù)據(jù)表名):
---- 取存貯過(guò)程的結(jié)果:
---- 一個(gè)完整的小例子源碼附后(其它功能讀者可加入)。
< %@ 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 > 數(shù)據(jù)庫(kù)列表 < 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 >