VBA connection to MySQL database and ODBC configuration (ODBC version and MySQL version if mismatch can occur driver and application errors)

Source: Internet
Author: User

db_connected = False

' Get database connection settings
Dsn_name = Trim (Worksheets ("Load Policy"). Cells (2, 5). Value)------(data SOURCE NAME in the ODBC configuration)
user_name = Trim (Worksheets ("Load Policy"). Cells (3, 5). Value)
Pass_word = Trim (Worksheets ("Load Policy"). Cells (4, 5). Value)

' Get Database Settings
db_name = Trim (Worksheets ("Load Policy"). Cells (8, 5). Value)--------Database name

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 ("Please set ODBC name")
Else
cn. ConnectionString = "Driver={mysql ODBC 5.1 DRIVER}; User id= "& User_name &"; Password= "& Pass_word &";D ata source= "& Dsn_name

ODBC configuration:

MySQL version: MySQL5.5

ODBC version: Mysql-connector-odbc-5.1.13-win32.msi

Mysql-connector-odbc-5.1.13-winx64.msi

After installing these two versions

Configuration:

1. Open the Control Panel

2. Search the data source and open

3. User dsn: Click Add, fill it out as required, make sure it's all right.

Note the driver there to click Apply.

VBA connection to MySQL database and ODBC configuration (ODBC version and MySQL version if mismatch can occur driver and application errors)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.