我正在使用OBDC连接器使用VBA连接到我的MySQL数据库。它目前在本地网络服务器(localhost)上运行,但可以通过我的PC的IP地址从网络上的其他PC访问。
在我的连接功能中,我有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