. Net connection MySQL database driver package MySQL. Data. dll (mysql-connector-net-5.0.8.1.exe) download As we all know ,. NET data access using ADO. net, and. net does not provide dedicated myql connection tools (such as SQL client of SQL Server), but mysql.com provides all the tools used for MySQL database connection. Here we useMySQL. Data. dll,It encapsulates the ADO. Net operations of all MySQL Databases in almost the same way as SQL Server (for example, sqlcommand in SQL Server is called mysqlcommand in MySQL ). The usage is as follows: 1) install the database driver package MySQL. Data. dll (mysql-connector-net-5.0.8.1.exe ). 2) introduce the mysql. Data. dll package in your own solution (project. The steps are as follows: A) Right-click the reference in solution. B) on the displayed page, click Add reference. C) Click browsing options in the pop-up dialog box. D) Find the mysql. Data. dll package you just installed in the search range text box. Note: The default path of MySQL. Data. dll is: C: \ Program Files \ mysql connector net 5.0.8.1 \ binaries \. NET 2.0 E) Click OK. 3) Write a connection to the MySQL databaseCode(Example :) Using mysql. Data. mysqlclient; <--- this space must be introduced // The server address of the data source database // Database Name of the database to be connected // User ID: User Name of the database // Password Database Password // Port Database port number (3306 can be omitted) Mysqlconnection dbconn = new mysqlconnection ("Data Source = 192.168.1.2; database = discuz; user id = root; Password = 123456; Port =; charset = gb2312 ;"); Try { dbconn. open (); }< br> catch (exception ex) {< br> // throw an exception } Finally { Dbconn. Close (); Dbconn. Dispose ();
}
Note: charset = gb2312 is used to solve Chinese garbled characters. This article is reproduced |