Thursday, 24 October 2013

MySql Connection Strings in Ado.Net

Today, MySql is open source database in the world. In to make connection to MySql , we have different connection strings. Basically it is not easy to remember different database connection strings in Ado.Net. So I am sharing some connection strings to connect to the MySql database using different drivers.

Using ODBC

// ODBC — MyODBC Driver — remote database

using System.Data.Odbc;

OdbcConnection conn = new OdbcConnection();

conn.ConnectionString = “Driver={MySql};; Option=131072; Port=3306; Stmt=; DataBase=DataBaseName; Uid=UserName; Pwd=Secret;” ;



// OleDb

using System.Data.OleDb;

OleDbConnection conn = new OleDbConnection();

conn.ConnectionString = “Provider=MySqlProv; Data Source=ServerName; User id=UserName; Password=Secret”;


Using .Net DataProvider

// .NET DataProvider from CoreLab

using CoreLab.MySql;

MySqlConnection conn = new MySqlConnection();

conn.ConnectionString =”Host=ServerName; DataBase=DataBaseName; Protocol=TCP; Port=3306; Direct=true; Compress=false; Pooling=true; Min Pool Size=0; Max Pool Size=100; Connection Lifetime=0;

User id=UserName;Password=Secret”;


MySql Connection Strings in Ado.Net