我们有一个Microsoft Access数据库+应用程序(在服务器A上),它使用系统DSN ODBC连接(在服务器A上)连接到SQL数据库服务器的远程SQL服务器(服务器B)。
用户远程打开此Access数据库,因为它位于服务器A上的共享位置。他们仍然必须在其计算机上创build本地ODBC连接以连接到服务器B.
有无论如何,他们可以访问Access数据库, 而不必创build一个本地的ODBC连接?
提前致谢
通过使用Access数据库中的一些代码,可以消除每台计算机上本地DSN的需要。 你当然仍然需要安装适当的ODBC驱动程序,但我希望你所需要的那个可能是Windows上的标准。
本地DSN将需要初始创build数据库。
以下是我用于dynamic链接到MySQL数据库的内容,因此您需要对其进行相应的编辑。 该代码从AutoExecmacros调用,或者可以手动运行或从窗体运行。
请注意,这不是我的代码,但我已经使用它很长一段时间,不记得我最初得到它的地方。 我所做的只是编辑它以适应我的要求。
Option Compare Database Public Function ReLinkTables() Dim dbPUBS As DAO.Database Dim tdfPUBS As DAO.TableDef Dim strTable As String Dim strConnect As String Dim InFile As Integer ' Set the following variables tosuit your DB connection Dim Server As String Dim Database As String Dim User As String Dim Password As String On Error GoTo 0 Set dbPUBS = Nothing Set dbPUBS = CurrentDb strConnect = "DRIVER={MySQL ODBC 3.51 Driver};" _ & "SERVER=" & Server & ";" _ & "DATABASE=" & Database & ";" _ & "UID=" & User & ";" _ & "PWD=" & Password & ";" _ & "OPTION=" & 1 + 2 + 8 + 32 + 2048 + 16384 ' Refresh Access linked tables For Each tdfPUBS In dbPUBS.tabledefs ' Only attempt to refresh link on tables that already ' have a connect string (linked tables only) If Len(tdfPUBS.Connect) > 0 Then strTable = tdfPUBS.Name ' Set the tables connection string tdfPUBS.Connect = strConnect ' and refresh the link tdfPUBS.RefreshLink End If Next ' Refresh Connect String for all Pass-Through Queries 'strMsg = "Refreshing links for all Pass Through Queries." 'DoCmd.Echo True, strMsg 'For Each qdfPUBS In dbPUBS.QueryDefs 'If Len(tdfPUBS.Connect) > 0 Then 'qdfPUBS.Connect = strConnect 'End If 'Next
结束function
定义到SQL Server的链接时不要使用DSN。 而是指定实际的连接string(应该是一个选项,但我没有使用Access多年)。