[英]Getting last insert id in Excel ADODB connection to MySQL database
[英]ADODB connection to MYSQL 8.0
I am using Windows 10, Excel 2016 and I'm trying to create an ADODB connection to a MYSQL80 instance on my laptop in Excel using VBA.
我收到錯誤消息“[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified。” I have tried this with both MYSQL ODBC 8.0 ANSI Driver and MYSQL ODBC 8.0 Unicode Driver. 運行時錯誤'-2147467259 (80004005)'
我已經建立了兩個 ODBC 連接,並且兩個連接都成功了。 請注意,它們是 64 位版本,因為我的操作系統是 64 位。
ODBC 連接
我的代碼包括
Public oSConn As New ADODB.Connection
Public Function GetSQLConnectionString() As String
GetSQLConnectionString = "Driver ={MYSQL ODBC 8.0 Unicode Driver};Server=localhost;Port=3306;Database=hstest;Uid=xxxx;Pwd=xxxx;"
End Function
並嘗試過
GetSQLConnectionString = "Driver ={MYSQL ODBC 8.0 ANSI Driver};Server=localhost;Port=3306;Database=hstest;Uid=xxxx;Pwd=xxxx;"
也試過這個,不包括端口=3306
還嘗試將 localhost 更改為 127.0.0.1
Sub UpLoadData()
oSConn.Open GetSQLConnectionString()
...
end sub
運行 OSConn.Open 行時發生錯誤。
我究竟做錯了什么?
我的一個朋友找到了答案。
GetSQLConnectionString = "驅動程序 ={MYSQL ODBC 8.0 U
應該
GetSQLConnectionString = "驅動程序={MYSQL ODBC 8.0 U
請注意刪除了 Driver 之后的空格。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.