Use MySQL and. net2.0 together

Source: Internet
Author: User
Tags odbc connection
The latest version of MySQL is 5.x. The first time I came into contact with MySQL, I used PHP when I was in my sophomore year. It seems that I still had version 4.x.

Mysql5 has added many new features to support stored procedures, triggers, views, and information architecture views...

The installation of MySQL is as complex as ever. It is often a failure prompt and there is no other cause.

This is an articleArticle, Compare MySQL and sqlserver, http://htm.winsteps.net/database/331.htm

The MySQL Chinese website http://www.mysql.cn/contains a small amount of information, which may be an installation helper.
To query the information, go to the MySQL website http://www.mysql.com /.

MySQL now provides a variety of connection tools (http://dev.mysql.com/downloads/connector/),. Net can be used under the connector/ODBC and connector/net.

ODBC connection efficiency may be slightly lower. It is best to use net direct connection.
This article introduces various Connection Methods http://www.mysql.com/news-and-events/press-release/release_2002_10.html

1: ODBC connection
The current version is 3.51. After installation, you can perform the following operations:

// String constr = "driver = {MySQL ODBC 3.51 driver}; server = localhost; database = test; uid = root; Password = ;";

// String Constr =   " Driver = {MySQL ODBC 3.51 driver}; server = localhost; database = test; user = root; Password =; option = 3; " ;
String Constr =   " Provider = MySQL ODBC 3.51 driver; server = localhost; database = test; uid = root; Password =; " ;

Try
{
Oledbconnection connection= NewOledbconnection (constr );
Connection. open ();
}
Catch (Exception ex)
{
MessageBox. Show (ex. Message );
}

2: net connection:
MySQL connector net 1.0.7: There are four versions of connector: net1.0, net.1, net2.0, and mono1.0. Free
CoreLab. MySQL 3.5: this is a commercial version with a trial period of 30 days.

BelowCodeIs an example of using MySQL connector net. Note: His parameter prefix is "?" Instead of "@". This problem is special. The prefix of parameter in CoreLab is "@".

  String Connstr = String. Format ( " Server = {0}; user id = {1}; Password = {2}; database = {3}; pooling = false; Port = 3308 " , " Localhost " , " Root " , "" , " Test " );
Try
{
Mysqlconnection myconn =   New Mysqlconnection (connstr );
Myconn. open ();
Mysqlcommand cmd = Myconn. createcommand ();

Cmd. Parameters. Add ( " ? Docname " , Mysqldbtype. varchar, 50 );
Cmd. Parameters [ 0 ]. Value =   " Test by code " ;
Cmd. Parameters [ 0 ]. Sourcecolumn =   " Docname " ;
Cmd. commandtext =   " Update t_docs set docname =? Docname where docid = 4 " ;
Cmd. executenonquery ();

This is an example of setting provider when using an Orm. Customprovider mysqlprovider =   New Customprovider ( " MySQL. Data " , " MySQL. Data. mysqlclient. mysqlconnection " , " MySQL. Data. mysqlclient. mysqldataadapter " );
Mysqlprovider. startdelimiter =   "" ; // Default is "/""
Mysqlprovider. enddelimiter =   "" ; // Default is "/""
Mysqlprovider. parameterprefix =   " ? " ; // Set the parameter prefix
Mysqlprovider. selectpagequery =   " Select * limit {0} offset {1} " ; // Set paging algorithm
Mysqlprovider. identityquery =   " Select last_insert_id () " ; // Set the function to retrieve the ID of the inserted record.

3: Ole connection:
There is no official support yet.

In vs2005, you can directly reference the DLL of for. net2.0. As for the commercial version, it takes a little effort and requires a license file (drag a conection component to form to automatically create the License)

Attachment, the connection string can be here to query the http://www.connectionstrings.com/, full enough.

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.