Server| Object | access | Built-in objects normally we have only heard of a class of ASP objects such as ADO, but there is also a little-known ASP Access object in ASP, which is the Sqlole.sqlserver object. Sqlole. SQL Server has direct access to the system properties of the. With Set oSQLServer = CreateObject ("SQLOLE.") SQL Server ") statement will result in the creation of a server object.
----To view a collection of databases in this server, you can phrase:
For each sqldb in osqlserver.databases
Response.Write Sqldb. Name ' will list all the databases, such as pubs and so on
Next
----To view a collection of data tables in a database, such as the pubs database, you can phrase:
Pubdatabase=osqlserver.databases ("pubs")
' oSQLServer is the SQL Server server object that was created earlier
For each dbtable in Pubdatabase.tables
Response.Write Dbtable.name
Next
----The following statement lists the data view in the database (pubs database)
Pubdatabase =osqlserver.databases ("pubs")
' oSQLServer is the SQL Server server object that was created earlier
For each dbview in Pubdatabase.views
Response.Write Dbview.text
Next
----The following statement lists the storage process in the database (pubs database)
Pubdatabase =osqlserver.databases ("pubs")
' oSQLServer is the SQL Server server object that was created earlier
For each dbsp in Pubdatabase.storedprocedures
Response.Write dbsp. Text
Next
----The results of the program running (Take the data table name):
----The results of the storage process:
----A complete small example of the source code attached (other features readers can join).
<%@ LANGUAGE = VBScript% >
< HTML >
< head >
< META name= "generator" content=
"Microsoft Developer Studio" >
< META http-equiv= "Content-type"
Content= "text/html; charset=gb2312 ">
< TITLE ></title >
<%
On Error Resume Next
Dim oSQLServer
Set oSQLServer = CreateObject ("SQLOLE. SQL Server ")
strserver = "DEP"
Strlogin = "sa"
Strpwd = ""
Osqlserver.connect strserver,strlogin,strpwd
% >
< body bgcolor= #ffffff >
Database list
< 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 >