查询在不同Web服务器上的数据库
使用ADO
dim cn as adodb.connection
dim cmd as adodb.command
dim rs as adodb.resultset
Set cn = New ADODB.Connection
With cn
.CursorLocation = adUseClient
.ConnectionString = gstrConnectionString
.Open
End With
Set adoCommand = New ADODB.Command
With adoCommand
.ActiveConnection = gadoConnection
.CommandType = adCmdStoredProc
.CommandText = "<stored proc name>"
Set adoRS = .Execute()
adoRS.CacheSize = 100
End With
for SQL Server the connection string would look something like the following:
Provider=SQLOLEDB.1;Password=<password>;Persist Security Info=True;User ID=<username>;Initial Catalog=<db_name>;Data Source=<servername>
使用DAO方式
Sub ConnectionObjectX()
Dim wrkJet as Workspace
Dim dbsNorthwind As Database
Dim wrkODBC As Workspace
Dim conPubs As Connection
Dim conPubs2 As Connection
Dim conLoop As Connection
Dim prpLoop As Property
' Open Microsoft Jet Database object.
Set wrkJet = CreateWorkspace("NewJetWorkspace", _
"admin", "", dbUseJet)
Set dbsNorthwind = wrkJet.OpenDatabase("<full UNC path>\<databasename.mdb>")
' Create ODBCDirect Workspace object and open Connection
' objects.
Set wrkODBC = CreateWorkspace("NewODBCWorkspace", _
"admin", "", dbUseODBC)
Set conPubs = wrkODBC.OpenConnection("Connection1", , , _
"ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers")
Set conPubs2 = wrkODBC.OpenConnection("Connection2", , _
True, "ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers")
Debug.Print "Database properties:"
With dbsNorthwind
' Enumerate Properties collection of Database object.
For Each prpLoop In .Properties
On Error Resume Next
Debug.Print " " & prpLoop.Name & " = " & _
prpLoop.Value
On Error GoTo 0
Next prpLoop
End With
' Enumerate the Connections collection.
For Each conLoop In wrkODBC.Connections
Debug.Print "Connection properties for " & _
conLoop.Name & ":"
With conLoop
' Print property values by explicitly calling each
' Property object; the Connection object does not
' support a Properties collection.
Debug.Print " Connect = " & .Connect
' Property actually returns a Database object.
Debug.Print " Database[.Name] = " & _
.Database.Name
Debug.Print " Name = " & .Name
Debug.Print " QueryTimeout = " & .QueryTimeout
Debug.Print " RecordsAffected = " & _
.RecordsAffected
Debug.Print " StillExecuting = " & _
.StillExecuting
Debug.Print " Transactions = " & .Transactions
Debug.Print " Updatable = " & .Updatable
End With
Next conLoop
dbsNorthwind.Close
conPubs.Close
conPubs2.Close
wrkJet.Close
wrkODBC.Close
End Sub
(责任编辑:admin)
- ·用DAO或ADO正确访问Access 2000
- ·Access开发网络共享版技巧(多人同时操
- ·access中ADO与DAO格式的区别和写法【总
- ·access执行操作查询的几种方法对比
- ·Access中CurrentDb().Execute 和DoCmd.
- ·[源创技巧]在ACCESS中使用代码来自动创
- ·更新访问权限 (Jet) 数据库中的 40 多
- ·【实例】ADO代码计算余额法
- ·DAO实现的子窗体记录分页显示
- ·分别使用DAO和ADO连接外部数据库和Sql
- ·怎样判断一个表是否存在于数据库中? (D
- ·处理加了密码的MDB文件
- ·谈ADO访问不同数据库的差别
- ·DAO基础(4)
- ·DAO基础(3)
- ·DAO基础(2)