mysql - 为什么连接字符串只能在开发机器上工作?
问题描述
我已经编写了 2 个程序,一个在 VB6 中,一个在 VBA for Excel 中。调用 mySQL 连接只能在开发机器上完美运行。尝试在任何其他机器上运行任一程序都会失败。代码如下:
Private Sub cmdErrors_Click()
On Error GoTo remote_err
Set myCon = New ADODB.Connection
strConnect = "Driver={MySQL ODBC 5.3 ANSI
Driver};Server=xxx.xxx.xxx.xxx;Port=3306;Database=cl22-budget;User=username;
Password=password;Option=3;"
myCon.ConnectionString = strConnect
myCon.Open
MsgBox "Connected"
myCon.Close
Set myCon = Nothing
Exit Sub
remote_err:
Dim ErrorCollection As Variant
Dim ErrLoop As Error
Dim strError As String
Dim iCounter As Integer
On Error Resume Next
iCounter = 1
strError = ""
Set ErrorCollection = myCon.Errors
For Each ErrLoop In ErrorCollection
With ErrLoop
strError = "error # " & iCounter & vbCrLf
strError = strError & "ADO Error # " & .Number & vbCrLf
strError = strError & " Description " & .Description & vbCrLf
strError = strError & " Source " & .Source & vbCrLf
MsgBox strError
iCounter = iCounter + 1
End With
Next
End Sub
解决方案
安装 ODBC 驱动程序并为您的数据库创建一个 DSN,它会在您提到您的服务器 ip 时询问服务器地址,然后它将起作用。
推荐阅读
- sql - 如何在 symfony 4 api 中获取仅显示所选数据的 sql 请求
- python - numpy:在“锯齿状”数组中矢量化随机数生成
- c - 如果我使用了所有动态分配的内存,我是否必须释放它?
- vba - VBA 函数下拉菜单
- javascript - 如何将变量传递给函数
- java - 是否可以在不影响主键的情况下删除jdbc db表中的一行
- java - 我无法在 android studio 中将适配器附加到 recyclerview
- python - ipython 或 jupyter 中的制表符完成是为了建议替代方案而寻求什么?
- php - 如何使用php在数组中搜索
- python - 使用 python 将包括图像的数据写入 xlsx 或 xls 文件