connecting to a mySql database from application to mySql connection

There are times when you want to connect to a mySql database from your code. By default the drivers for mySql are not packaged with so you need to include an external dll into your project.

this dll contains all the necessary code required to provide the abstraction that .net developers are used to with while working on ADO.NET. You add the dll into your project and next moment you are creating instances of MySqlConnection, MySqlDataReader and hence forth things are same as you would do with your mssql database connection code.
The dll is available to download at the end of this article.

How to use

  1. download
  2. copy it to the bin folder of your application (use windows explorer to browse to the project location (bin folder as it’s generally not visible in Visual Studio)
  3. Add a reference of the said dll into your project
  4. Add using MySql.Data.MySqlClient; inside your code
  5. Make objects of MySqlConnection, MySqlDataReader, MySqlCommand and use them as you would use SqlConnection, SqlDataReader, SqlCommand respectively