我正在使用OBDC连接器来使用VBA连接到我的MySQL数据库。它目前运行在本地网络服务器(本地主机)上,但可通过我的PC的IP地址从网络上的其他PC访问。Excel VBA连接到远程MySQL数据库
在我的连接功能,我有localhost的位置,但是当我将其更改为我的IP地址,我得到一个
[MySQL][ODBC 5.2 Driver] (my computer name) is not allowed to connect to this MySQL server
错误。
我认为这是一个安全问题。有任何解决这个问题的方法吗?
这里是我的连接功能:
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
source = "MySQL"
location = "192.168.1.60"
user = "root"
password = ""
database = "database name"
mysql_driver = "MySQL ODBC 5.2 ANSI Driver"
//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 to the selected source
Set OpenConnection = New ADODB.connection
OpenConnection.CursorLocation = adUseClient
Call OpenConnection.Open(connectionString)
End Function
2013-10-18
harryg