Connect MySQL Database in ASP.NET

Connect MySQL Database in Asp.net

Here is the way to connect your MySQL Database into Asp.net Code page. First you have to download mysql.data.dll file Click here. In this page download 32 bit version MySQL connecter.exe file.

In your project Page visual 2008 page right click your project -> Add reference -> select that mysql.data.dll file.

There is one new folder created in the name of Bin in that folder there is two reference file created in the name of Mysql.data.dll and Mysql.data.dll.refresh

Now in your code window you have to include the reference in the following format.

  1. using System.Data;  
  2.   
  3. using MySql.Data.MySqlClient;  

After adding reference is completed then you have to establish the database connection, like connection string.

The connection string is as follows.

  1. MySqlConnection con = new MySqlConnection("Data Source=Servername;port=3306;Initial Catalog=databasename; User Id=ID;password=psw;");  

 

Server Name field mentions the server IP address as 182.00.00.00 or mentions it as localhost (which  means the server is handled by you) or otherwise mentions the server IP.

Insert command coding:

  1. MySqlCommand cmd = new MySqlCommand("insert into table_name (table_fields) vlues(“……..”)",con);