MySQL database connection method (. net)

Source: Internet
Author: User
Tags dsn

1. Through the ADO connection (in the database connection string for the Chinese seems to be unable to use)

Need to add MySql.Data.dll (available by installing Mysql-connector-net-6.8.3.mis)

Reference MySql.Data.dll

Invocation mode

String connectionstring= "server=localhost;port=3306;database=dbtest;uid=root;pwd=111;"

Mysqlconnection conn = new Mysqlconnection (connectionString))

Conn. Open ();

2. Using ODBC

32-bit MySQL installation Mysql-connector-odbc-5.1.5-win32.msi

64-bit MySQL installation Mysql-connector-odbc-5.1.12-winx64.msi

If it is a 32-bit operating system, you can add the DSN directly in the ODBC Administrator, if the 64-bit operating system, the MySQL version is 64-bit can be added directly dsn,mysql is 32-bit, you need to open C:\Windows\SysWOW64\ Odbcad32.exe to add a DSN. After you add it, you can add tests in the Server Explorer, vs-> view, to see if it is successful.

32-bit ODBC configuration Manager

String constr = "Driver={mysql ODBC 5.1 Driver}; Server=localhost; Port=3306;database= Chinese; User=root; password=111;option=3; ";

OdbcConnection conn = new OdbcConnection (CONSTR);

Conn. Open ();

3. Use MySQLDriverCS.dll (not available on 64-bit systems, no 64-bit DLLs available temporarily)

Direct reference to MySQLDriverCS.dll (can be found directly online)

Using Mysqldrivercs;

Mysqlconnection conn = new Mysqlconnection (new mysqlconnectionstring ("localhost", "Test", "root", ""). asstring);

Conn. Open ();

Related Article

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.