|
以下是引用zxh在2004-3-27 17:54:48的发言:
我想用ACCESS做前台界面,用SQL数据库做后台,我搜索了很多旧贴,但是都不知道怎样解决远程链接表问题,我不想通过ODBC来链接,因为DSN上面可以看到我的服务器IP和登录用户ID,有哪位高人可以教我如何不通过DSN解决这个远程链接的问题吗?谢谢!
因为我刚接触这方面,所以最好能举个例子,例如:我的ACCESS前台的链接表如何可以连到我的服务器上的SQL数据库中的表???? 非常感谢!
我的理解,你所说的“远程”是指基于TCP/IP访问SQL SERVER数据库。如果我的理解不正确的话请跟贴说明。
你的链接表的连接字符串可以定义为:
ODBC;DRIVER=SQL Server;SERVER=<你的服务器名>;UID=<数据库登录名>WD=<登录密码>;DATABASE=<数据库名>
例如:
Sub RefreshLinkX()
Dim dbsCurrent As Database
Dim tdfLinked As TableDef
' Open a database to which a linked table can be
' appended.
Set dbsCurrent = OpenDatabase("DB1.mdb")
' Create a linked table that points to a Microsoft
' SQL Server database.
Set tdfLinked = _
dbsCurrent.CreateTableDef("AuthorsTable")
tdfLinked.Connect = _
"ODBC;DRIVER=SQL Server;SERVER=192.168.0.1;UID=saWD=;DATABASE=pubs"
tdfLinked.SourceTableName = "authors"
dbsCurrent.TableDefs.Append tdfLinked
' Display contents of linked table.
Debug.Print _
"Data from linked table connected to first source:"
RefreshLinkOutput dbsCurrent
' Display contents of linked table.
Debug.Print _
"Data from linked table connected to second source:"
RefreshLinkOutput dbsCurrent
' Delete linked table because this is a demonstration.
dbsCurrent.TableDefs.Delete tdfLinked.Name
dbsCurrent.Close
End Sub
Sub RefreshLinkOutput(dbsTemp As Database)
Dim rstRemote As Recordset
Dim intCount As Integer
' Open linked table.
Set rstRemote = _
dbsTemp.OpenRecordset("AuthorsTable")
intCount = 0
' Enumerate Recordset object, but stop at 50 records.
With rstRemote
Do While Not .EOF And intCount < 50
Debug.Print , .Fields(0), .Fields(1)
intCount = intCount + 1
.MoveNext
Loop
If Not .EOF Then Debug.Print , "[more records]"
.Close
End With
End Sub
这样话,就不需要设置DSN |
|