在 Access 2003 中编辑链接表信息

发布于 2024-10-07 18:12:17 字数 349 浏览 0 评论 0原文

我有一个 Access 2003 数据库,其中包含与 SQL Server 2005 数据库的链接表。用于在 Access 和 SQL Server 之间创建 ODBC 连接的用户信息(密码)最近已更新。

当我打开 Access 数据库并尝试编辑链接表信息时,我就可以打开表并查看我的数据。但是,当我关闭 Access 并重新打开 Access 数据库时,密码信息似乎已恢复,并且出现 ODBC 连接错误。

有人知道我做错了什么吗?

作为后续行动,我们似乎有大约十几个带​​有大量链接表的 Access 数据库都需要此更新。这是更新此信息的最佳方式吗?链接表似乎是使用不同的计算机创建的,因为 ODBC 连接中指定的工作站 ID 不同。

I have an Access 2003 database with linked tables to a SQL Server 2005 database. The user information (the password) that is used to create an ODBC connection between Access and SQL Server was recently updated.

When I open the Access database, and try to edit the Linked table information I am then able to open the tables and see my data. However, when I close Access and and reopen the Access database it appears the password informtion has revereted back and I get an ODBC connection error.

Anyone know what I am doing incorrectly?

As a follow up, it appears we have about a dozen Access databases with numerous linked tables that all need this update. Is this the best way to update this information? The linked tables seem to have been created using different machines as the Workstation-ID specified in the ODBC connection is different.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那小子欠揍 2024-10-14 18:12:17

编写一个例程,从 TableDef 更新 Connect 属性并使用 RefreshLink 保存更改。

Write a routine, that update the Connect Property from the TableDef and save the change with RefreshLink.

尸血腥色 2024-10-14 18:12:17

链接表管理器 (LTM) 的问题在于当您拥有实际上链接到 SQL 视图的链接表时。在这种情况下,LTM 将重新链接“表”而不为它们重新分配适当的 PK,并且它们将变得不可更新。
我已经编写了一些从 VBE 开始的代码,这是一件快速而肮脏的事情,但如果您需要的话,您肯定可以对其进行调整。
有 2 个子程序,一个用于表,一个用于通路查询。

Option Compare Database
option explicit

Const kOld = "remote.g"  'string to identify old server
'new server odbc string
Const kConnLux = "ODBC;DRIVER=SQL Server Native Client 10.0;SERVER=xxxx;UID=yyyy;PWD=zzzz;"

Sub UpdateTables()
    Dim db As Database, td As TableDef
    Dim hasIndex As Boolean, strSql As String

    Set db = CurrentDb
    For Each td In db.TableDefs
        If InStr(1, td.Connect, kOld) > 0 Then  'lien vers CE serveur ?
            If td.Name Like "dbo_vw*" And td.Indexes.count = 1 Then 'table = vue attachee --> pbl de clef primaire
                strSql = "CREATE INDEX " & td.Indexes(0).Name & " ON [" & td.Name & "](" & td.Indexes(0).Fields & ")"
                ' convert field list from (+fld1;+fld2) to (fld1,fld2)
                strSql = Replace(strSql, "+", "")
                strSql = Replace(strSql, ";", ",")
                hasIndex = True
            Else
                hasIndex = False
            End If
            td.Connect = kConnLux
            td.RefreshLink
            Debug.Print td.Name
            If hasIndex And td.Indexes.count = 0 Then
                ' if index now removed then re-create it
                CurrentDb.Execute strSql
            End If
        End If
    Next td
    Debug.Print "Done"
End Sub

Sub UpdateQueries()
    Dim db As Database
    Dim td As QueryDef
    Set db = CurrentDb
    For Each td In db.QueryDefs
        If InStr(1, td.Connect, kOld) > 0 Then
            td.Connect = kConnLux
            Debug.Print td.Name, td.Connect
        End If
    Next td
End Sub

The problem with Linked Table Manager (LTM), is when you have linked tables that are in fact links to SQL Views. In that case, LTM will relink the "tables" without reassigning them the proper PK, and they will become non updatable.
I have written some code that I used to start from VBE, it is a quick and dirty thing, but you could surely adapt that if you need it.
There are 2 subs, one for the tables, and one for the passthru queries.

Option Compare Database
option explicit

Const kOld = "remote.g"  'string to identify old server
'new server odbc string
Const kConnLux = "ODBC;DRIVER=SQL Server Native Client 10.0;SERVER=xxxx;UID=yyyy;PWD=zzzz;"

Sub UpdateTables()
    Dim db As Database, td As TableDef
    Dim hasIndex As Boolean, strSql As String

    Set db = CurrentDb
    For Each td In db.TableDefs
        If InStr(1, td.Connect, kOld) > 0 Then  'lien vers CE serveur ?
            If td.Name Like "dbo_vw*" And td.Indexes.count = 1 Then 'table = vue attachee --> pbl de clef primaire
                strSql = "CREATE INDEX " & td.Indexes(0).Name & " ON [" & td.Name & "](" & td.Indexes(0).Fields & ")"
                ' convert field list from (+fld1;+fld2) to (fld1,fld2)
                strSql = Replace(strSql, "+", "")
                strSql = Replace(strSql, ";", ",")
                hasIndex = True
            Else
                hasIndex = False
            End If
            td.Connect = kConnLux
            td.RefreshLink
            Debug.Print td.Name
            If hasIndex And td.Indexes.count = 0 Then
                ' if index now removed then re-create it
                CurrentDb.Execute strSql
            End If
        End If
    Next td
    Debug.Print "Done"
End Sub

Sub UpdateQueries()
    Dim db As Database
    Dim td As QueryDef
    Set db = CurrentDb
    For Each td In db.QueryDefs
        If InStr(1, td.Connect, kOld) > 0 Then
            td.Connect = kConnLux
            Debug.Print td.Name, td.Connect
        End If
    Next td
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文