服务器已移动,现在 MS Excel 2003 查询将无法工作

发布于 2024-08-08 12:03:24 字数 318 浏览 7 评论 0原文

我们使用 MS Query 从各种数据库检索数据以创建管理指标(即在 Excel 中,转到数据...导入外部数据...新数据库查询)。 SQL 查询和参数(主要是 conn 字符串)由 Excel 自动存储在电子表格中。

但是,我们最近将其中一个数据库移至新服务器。因此,Excel 在尝试刷新数据时提示我们建立新的 ODBC 连接,但它不会接受新值。我们可以很好地创建新查询,因此 ODBC 连接已正确设置,但我们无法更改任何查询。

有没有办法以编程方式或以其他方式更改这些设置中的 IP 地址?我尝试在十六进制编辑器中更改 xls 文件(IP 地址在那里可见),但随后显示工作簿已损坏。

We use MS Query to retrieve data from various databases to create management metrics (i.e. within Excel, go to Data...Import External Data...New Database Query). The SQL query and parameters (mostly conn string) are automatically stored by Excel within the spreadsheet.

However, we recently moved one of our databases to a new server. As a result, Excel prompts us for a new ODBC connection when trying to refresh the data, but it will not accept the new values. We can create new queries fine, so the ODBC connection is set up correctly, but we cannot change any queries.

Is there a way to programatically or otherwise change the IP address within these settings? I tried changing the xls file in a hex editor (the IP addresses are visible there), but it then says the workbook is corrupt.

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

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

发布评论

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

评论(1

紧拥背影 2024-08-15 12:03:24

如果您需要更改查询的连接字符串,此宏将为活动工作簿中的所有查询更改它(您不必将代码存储在要更改的工作簿中)。

我提供了两个示例连接字符串 - 一个提供 dsn,一个提供服务器/数据库。如果您的 DSN 在创建新查询时没问题,请先尝试 DSN。如果您使用 SQL Server 版本,请调整该版本。

此外,一种具有标准安全性(uid、pwd),另一种使用基于 Windows 的安全性(可信连接)。适当混合和搭配。

Sub ChangeAddress()

Dim qt As QueryTable
Dim wks As Worksheet

Const strNEW_CONN_DSN As String = "ODBC;DSN=MyDSN;Description=MyDescription;UID=myid;PWD=mypwd;"

Const strNEW_CONN_SQL as String = "Driver={SQL Server Native Client 10.0};Server=myServerAddress;Database=myDB;Trusted_Connection=yes;"

For Each wks In ActiveWorkbook.Worksheets
    For Each qt In wks.QueryTables
        qt.Connection = strNEW_CONN_DSN
    Next qt
Next wks
End Sub

If you need to change the connection string of your queries, this macro will change it for all queries in the active workbook (you don't have to store the code in the workbook to be changed).

I include two sample connection strings - one supplies the dsn, one supplies the server/database. If your DSN is fine when creating new queries, try the DSN one first. Adjust SQL Server version if you use that one.

Also, one has standard security (uid,pwd) and the other uses windows-based security (trusted connection). Mix and match as appropriate.

Sub ChangeAddress()

Dim qt As QueryTable
Dim wks As Worksheet

Const strNEW_CONN_DSN As String = "ODBC;DSN=MyDSN;Description=MyDescription;UID=myid;PWD=mypwd;"

Const strNEW_CONN_SQL as String = "Driver={SQL Server Native Client 10.0};Server=myServerAddress;Database=myDB;Trusted_Connection=yes;"

For Each wks In ActiveWorkbook.Worksheets
    For Each qt In wks.QueryTables
        qt.Connection = strNEW_CONN_DSN
    Next qt
Next wks
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文