简体   繁体   English

VBA:连接到mysql,在ADODB.Connection上发出

[英]VBA : Connection to mysql, issue on ADODB.Connection

I am trying to connect to Mysql via VBA in access. 我试图通过访问中的VBA连接到Mysql。 I have created my DSN on my computer, the test connection works well. 我已经在计算机上创建了DSN,测试连接运行良好。 In VBA I am doing this : 在VBA中,我正在这样做:

Dim S As String
    Set oConnect = New ADODB.Connection
    S = "DRIVER={MySQL ODBC 5.3 ANSI Driver};" & _
        "SERVER=localhost ;" & _
        "DATABASE=myDataBase ;" & _
        "USER=root;" & _
        "PASSWORD=root;" & _
        "Option=3"
    oConnect.Open S

I am getting this error : 我收到此错误:

Defined type by user is not defined. 未定义用户定义的类型。

I have referenced Microsoft Activex Data object 2.8. 我已经引用了Microsoft Activex数据对象2.8。

Thanks. 谢谢。

The right way is : 正确的方法是:

Driver={mysql};  & _
database=nameDB; & _
server=NameServer; & _
uid=NameUser; & _
pwd=PassWord; & _
option=16386;

Change USER for uid and PASSWORD for pwd USER更改为uid ,将PASSWORD更改为pwd

And don't forget to active the library : Microsoft AtiveX Data Objects 2.x Library . 并且不要忘记激活该库: Microsoft AtiveX Data Objects 2.x Library

Change your S to : 将您的S更改为:

 S = "DRIVER={MySQL ODBC 5.3 ANSI Driver};" & _
     "SERVER=localhost ;" & _
     "DATABASE=myDataBase ;" & _
     "uid=root;" & _
         "pwd=root;" & _
         "Option=3;"
oConnect.ConnectionString  S
oConnect.Open

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM