为什么连接字符串仅在开发机上工作?

时间:2018-10-14 09:02:23

标签: mysql excel vba excel-vba odbc

我写了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

1 个答案:

答案 0 :(得分:0)

安装ODBC驱动程序并为您的数据库创建一个DSN,然后在其中询问服务器IP的地方询问服务器地址,然后它将起作用。

相关问题