gpt4 book ai didi

mysql - Excel 连接 MySQL 运行时错误 -2147467259 (80004005)

转载 作者:行者123 更新时间:2023-11-29 15:25:56 25 4
gpt4 key购买 nike

我这里有这段代码:

Sub Example()
Dim Conn As New Connection

Conn.ConnectionString = "Server=localhost;Port=3306;Database=testing;Uid=root;Pwd=test;"
Conn.Open

Dim rs As New Recordset
Dim sql As String
sql = "Select productcode from labels" 'put spec of desired table here
rs.Open sql, Conn
If Not rs.EOF Then
Range("a1").CopyFromRecordset rs
End If
rs.Close
Set rs = Nothing
Conn.Close
Set Conn = Nothing
End Sub

并获取此错误代码:

run-time error -2147467259 (80004005)

我该如何解决这个问题?我想做的是:

无需使用插件即可将数据从 MYSQL 导出到 Excel。

最佳答案

我需要使用有效的服务器、数据库、用户 ID 和密码更新 ConnectionString,因为我这边使用的是 SQL Server。

现在,如果我在 sql = "Select Productcode from labels" 行暂停代码并运行它,代码将失败,突出显示 ConnectionString 行并返回以下内容错误消息:

enter image description here

根据错误消息,我需要指定默认驱动程序以使代码正常运行。就我而言,它看起来像这样:

Conn.ConnectionString = "Driver={SQL Server};Server=...

由于您使用的是 MySQL,我建议尝试以下方法之一(检查 ODBC 版本):

驱动程序={MySQL ODBC 5.2 UNICODE 驱动程序};

驱动程序={MySQL ODBC 5.2 ANSI 驱动程序};

关于mysql - Excel 连接 MySQL 运行时错误 -2147467259 (80004005),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59093091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com