Wednesday, September 15, 2010

.Net MySql Connector

My colleague wasfighting with new Database server and the interesting thing was the server is "MySql",.For us Microsoft people those are little bit odd (we always play with our well structured "MSSQL"). He was actually searching to get a solution to connect to this new DB from his .Net code. Lots of solution tells to install ODBC Driver to connect to MySql.

But I said, no there is something very straight forward like out "System.Data.SqlClient" or "System.Data.OracleClient" namespaces we have, those are available inbuilt with .Net Framework. So for this case I suppose this should be a matter of an assembly reference. And I tried, hardly searched, and atlast Google brought the result.

There is one connection "Mysql-Connector" assembly available in the "Mysql" site itself. From there you can download and as a reference to you project.

http://dev.mysql.com/downloads/connector/net/5.0.html

Now everything as usual, very straight forward . the code goes as like bellow.

//Add reference namespace
using MySql.Data.MySqlClient;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//create connection object, command...
MySqlConnection Con = new MySqlConnection();
}
}

So we did it... once again I love .Net :)

No comments: