Today, MySql is open source database in the world. In Ado.net 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}; Server=db.domain.com; Option=131072; Port=3306; Stmt=; DataBase=DataBaseName; Uid=UserName; Pwd=Secret;” ;
conn.Open();
Using OLEDB
// OleDb
using System.Data.OleDb;
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = “Provider=MySqlProv; Data Source=ServerName; User id=UserName; Password=Secret”;
conn.Open();
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”;
conn.Open();
MySql Connection Strings in Ado.Net