1

Can anyone help me to clarify that how to connect mysql server with asp.net and all the relevant query command like select,insert etc. regards shashi

1 Answer 1

5

You need to download the MySQL Connector .Net, and install it.

Then, instead of using a SqlProvider for your application, you change it to a MySQL Provider, and add a reference to the MySQL.Data assembly that was installed by the connector to your project. Then add a connection string like usual to your web.config file:

<connectionStrings>
    <add name="myConnString" 
         connectionString="Server=yy;Database=xx;Uid=zzz;Pwd=abcdefg;" 
         providerName="MySql.Data.MySqlClient"/>
</connectionStrings>

After that it's pretty much the same. The provider model means that the MySQL connector provides all the same objects that you're used to, like MySQLConnection, MySQLCommand, etc.

MySqlConnection conn;
using(conn=new MySqlConnection(ConnectionString)){

    MySqlCommand cmd = new MySqlCommand("SELECT * FROM myTable");

    conn.Open();
    var reader = cmd.ExecuteReader();

    /* process records.... */

    conn.Close();
}
Sign up to request clarification or add additional context in comments.

1 Comment

+1. You will also need using MySql.Data.MySqlClient; at the top of your source file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.