如何在excel 2007中使用vba连接到mysql

时间:2015-04-21 20:48:40

标签: mysql vba

我使用下面的代码连接到mysql,我已经安装了mysql odbc connector 5.3版。

'Connect to database
Function CnnOpen(ByVal ServerName As String, ByVal DBName As String, _
ByVal TblName As String, ByVal User As String, ByVal PWD As String)

    Dim CnnStr As String
    Set Cnn = CreateObject("ADODB.Connection")
    Cnn.CommandTimeout = 15
    CnnStr = "DRIVER = {MySql ODBC 5.3 Driver}; SERVER =" & ServerName & _
             "; Database =" & DBName & "; USER =" & User & "; PASSWORD =" _
             & PWD & "; Option=3"
    Cnn.ConnectionString = CnnStr
    Cnn.Open
End Function

我有以下错误:

  

运行时错误' -2147467259(80004005)':   [Microsoft] [ODBC驱动程序管理器]未找到数据源名称和   没有指定默认驱动程序

代码中是否有错误的连接字符串或错误?请帮忙。

0 个答案:

没有答案