主要是创建链接服务器方式:
EXEC sp_addlinkedserver
'slk_access',
'OLE DB Provider for Jet',
'Microsoft.Jet.OLEDB.4.0',
'D:\abc.mdb'
GO
SELECT *
FROM slk_access...Cust;
Cust 是access中的表名
Private conn0 As New ADODB.Connection
Private rs0 As New ADODB.Recordset
Private ConnString As String
Private SQL As String
Private Sub Command1_Click()
Dim a(10)
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" + "C:\inetpub\wwwroot\IZLAN.mdb" + ";Persist Security Info=False" + ";" & _
"Jet OLEDB:Database Password=False"
SQL = "Select * From 表名"
If conn0.State <> 1 Then
conn0.Open (ConnString)
End If
rs0.Open SQL, conn0, adOpenKeyset, adLockPessimistic
For i = 1 To rs0.RecordCount
a(0) = rs0.Fields(1)
a(1) = rs0.Fields(2)
a(2) = rs0.Fields(3)
rs0.MoveNext
Next i
Me.Caption = a(0) & a(1) & a(2)
Set rs0 = Nothing
Set conn0 = Nothing
End Sub
在SQL查寻分析器中输入代码:
--1、开启功能:
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
--2、查寻:
SELECT *
FROM OpenDataSource( 'Microsoft.ACE.OLEDB.12.0',
'Data Source="C:\inetpub\wwwroot\IZLAN.mdb";UserID=Admin;Password=')...[数据库表名]
完后就可以看到ACCESS中的数据了!