How to be in. NET to access the MySQL database

Source: Internet
Author: User
Tags dsn odbc ole mysql database
Summary
As a small relational database, MySQL has won the favor of a large number of small and medium-sized enterprises and individual users with the features of low price, powerful function, decent speed and open source. But in. NET access to the MySQL database is not as convenient as it might be, because the compatibility of. NET OLE DB Data provider and MySQL is not ideal. This article introduces two kinds of in. NET to access the MySQL database, and the two methods do a simple performance comparison.
Introduction
If you are not only working in a large group, you will have access to MySQL, although it does not support transaction processing, stored procedures, but it provides the functionality will be able to meet most of your needs, in addition, concise MySQL has some of its unique advantages, in some cases, It is even faster than a large database.
So how in. NET to access the MySQL database? Many people may soon say: OLE DB, but in fact, the. NET OLE DB Data provider does not have access to MySQL, and if you do, the system prompts you: "NET Data OLE DB provider (SYSTEM.DATA.ODBC) does not support MSDASQL provider (Microsoft OLE DB provider for ODBC drivers). "What's the reason I don't know, according to Mysqldrivercs's author is that it was" abandoned by the owner ", hehe, maybe some stories.
Fortunately, we have other options, here are two ways to access the MySQL database.
Using Odbc.net
Odbc. NET (full name ODBC. NET Data Provider) is a free. NET Framework add-on that needs to be downloaded to Microsoft's Web site: http://download.microsoft.com/download /dasdk/install/1.0.4030.0/w98nt42kmexp/en-us/odbc_net.msi, it requires the system to have MDAC 2.7 or later installed. Additionally, you will need to install the ODBC driver for MySQL, with the download address: http://www.mysql.com/downloads/api-myodbc-2.50.html, and you will need to configure DSN in the ODBC Data Source Administrator.
In the design of objects, ODBC. NET also like Oledb,sql, respectively, for OdbcConnection, OdbcCommand, OdbcDataAdapter, OdbcDataReader, usage is exactly the same, if you want to use ODBC. NET to replace the previous OLE DB. NET Data Provider, you can actually modify your program by looking for replacements.
The following is a code example:
Try
{
String constr = "dsn=mysql;" + "uid=;" + "pwd=";;
conn = new OdbcConnection (CONSTR);
Conn. Open ();
string query = "INSERT INTO test.dbtable values10, ' disksidkfsdi ', ' asdfaf ', ' adsfasdf ')";
string tmp = NULL;
OdbcCommand cmd = new OdbcCommand (query, conn);
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.