我想將一個excel檔案與一個專案的MySQL服務器連接起來,所以我在互聯網上搜索了一個解決方案。我找到了一些,但都是舊的,我不喜歡 8-10 歲的方法和驅動程式。
我得到的只是 [Microsoft][ODBC Driver Manager] Data source name not found, and no default driver specified
所以,我設定了以下設定:
- MySQL 8.0 服務器(在 Oracle 云中的 Ubuntu 服務器上)64 位,ODBC 連接器 8.0 Unicode 64 位
- Office 365 64 位
我試圖與一些方法建立聯系,但它們給出了同樣的錯誤:
[Microsoft][ODBC Driver Manager] Data source name not found, and no default driver specified
Public Function OpenConnection() As ADODB.Connection
''This function requires the "Microsoft ActiveX Data Objects" Library (Choose v2.8 from references for compatibility across Office versions)
Dim source As String, location As String, user As String, password As String
location = My server IP
user = "ExcelTest"
password = "Pass"
database = "Test"
mysql_driver = "MySQL ODBC 8.0 Driver" ''Tried "MySQL ODBC 8.0 Unicode Driver" too
''Build the connection string
Dim connectionString As String
connectionString = "Driver={" & mysql_driver & "};Server=" & location & ";Database=" & database & ";UID=" & user & ";PWD=" & password
''Create and open a new connection
Set OpenConnection = New ADODB.Connection
OpenConnection.CursorLocation = adUseClient
Call OpenConnection.Open(connectionString)
End Function
通常我會找到一個很好的教程或演練,但這次沒有最新的。
我是的。我很確定所有的東西都是 64 位的。
我不知道在哪里搜索請幫助
uj5u.com熱心網友回復:
首先使用 Windows ODBC 資料源管理器測驗驅動程式是否安裝正確。
Option Explicit
Sub test()
Dim conn
Set conn = OpenConnection()
With conn
.CursorLocation = adUseClient
MsgBox "Connected to " & .DefaultDatabase, vbInformation
End With
End Sub
Public Function OpenConnection() As ADODB.Connection
Const location = ""
Const user = ""
Const password = ""
Const database = "test"
Const mysql_driver = "MySQL ODBC 8.0 Unicode Driver"
' Build the connection string
Dim s As String
s = "Driver={" & mysql_driver & "};Server=" & _
location & ";Database=" & _
database & ";UID=" & _
user & ";PWD=" & password
Debug.Print s
' Open connection
Set OpenConnection = New ADODB.Connection
OpenConnection.Open s
End Function
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/528454.html
