标签:io sp on 数据 bs cti amp as new
db_connected = False
‘获取数据库连接设置
dsn_name = Trim(Worksheets("加载策略").Cells(2, 5).Value) ------(ODBC配置中的DATA SOURCE NAME)
user_name = Trim(Worksheets("加载策略").Cells(3, 5).Value)
pass_word = Trim(Worksheets("加载策略").Cells(4, 5).Value)
‘获取数据库设置
db_name = Trim(Worksheets("加载策略").Cells(8, 5).Value) --------数据库名
Set cn = New Connection
Set rs = New Recordset
Set rs1 = New Recordset
Set cmd = New Command
Set a_App = New Application
If dsn_name = "" Then
MsgBox ("请设置ODBC名称")
Else
cn.ConnectionString = "DRIVER={MySQL ODBC 5.1 Driver};User ID=" & user_name & ";Password=" & pass_word & ";Data Source=" & dsn_name
ODBC配置:
MySQL版本:MySQL5.5
ODBC版本:mysql-connector-odbc-5.1.13-win32.msi
mysql-connector-odbc-5.1.13-winx64.msi
安装完这两个版本
配置:
1.打开控制面板
2.搜索数据源然后打开
3.用户DSN:点击添加,按要求填写好,确定就行了
注意驱动程序那里要点击应用。
VBA连接MySQL数据库以及ODBC的配置(ODBC版本和MySQL版本如果不匹配会出现驱动和应用程序的错误)
标签:io sp on 数据 bs cti amp as new
原文地址:http://www.cnblogs.com/zigewb/p/4138256.html