我正在使用 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