MySql Connector For .net


How to connect to MySql data base using MySql Connector for .net in Visual Studio

In this article I will show you an easier and efficient way of how one can integrate MySql database and .net

Why to do so ?
Because as we know MySQL is an open source, and its good to work on open souces, as we can customize it as per our need/requirement

And "MySql connectors for .net" is also an open source tool provided by MySql community, so you can customize it too.
You can download the connector & Source code here


http://www.mysql.com/downloads/connector/net/


Ok, now there are two ways to implement MySql connector

First


If you have the installation file of the MySql connector:
Then follow the steps

1. Open the setup file and install the MySql Connector
2. After installation is finished, open Visual Studio.
3. Open a new/existing project/file
4. View the "Solution Explorer"
5. In Solution Explorer, right click on the "REFERENCE" folder
6. Click "on Add Reference"
7. An Add Reference Dialog box will open up
8. Under ".NET" catagory, search for " MySql.Data", select it and click "ok"
9. You will see in Solution Explorer, after expanding the Reference Folder, a new reference
"MySql.Data" has been added.
10. Now in your .cs/.vb files include the followilg in "using"
using MySql.Data;
using MySql.Data.MySqlClient;


Second


If you have the Source codes of the "MySql Connector for .Net".
{Note: Use this only if you want to customize your MySql Methods, such as the dataapapter or the commandbuilder or etc}
Follow the steps

1. Extract the folder
2. Open Visual Studio
3. Create/Open a new/existing project
4. Go to "File menu" --> Add --> Existing Project
5. A "Add Existing Project" Dialog box will open up, in there browse to the folder which you have extracted earlier.
Inside that folder you will find another folder "MySql.Data"
Inside "MySql.Data" Folder you will find "Provider" Folder
Inside "Provider" Folder you will find "MySql.Data Visual C# Project file"
Click on it and click open.
6. Now view "Solution Explorer", you will find a new project has been added to the solution
7. Now build the MySql.Data Project
(Remember that now you have two projects in your solution. One that you have created or opened previously in Step 2
Second is the MySql.Data Project ,you have to build this project only for now
because it will create a MySql.Data.dll in its \\bin\\debug folder )
8. Add the "MySql.Data.dll" created in step 7 to the reference folder of your project that you have created or opened
9. Now in your .cs/.vb files include the followilg in "using"
using MySql.Data;
using MySql.Data.MySqlClient;


Here the difficult parts are done,
If you have used ADO.Net before using SQLServer as a database, then it will be very easy for you, besause the methods are
all similar to the "System.Data.SqlClient"
For eg:

System.Data.SqlClient MySql.Data.MySqlClient
SqlConnection MySqlConnection
SqlDataReader MySqlDataReader
SqlCommand MySqlCommand
Sql....... MySql.......


If you have any doubts give a response

Cheers
Paul

Reference: http://www.mysql.com/downloads/connector/net/


Comments

Author: Diane07 Oct 2010 Member Level: Bronze   Points : 1

Only the source zips are available - not, unfortunately, the installer.

The source won't build - I get the following error:
Error 2 Cryptographic failure while signing assembly 'C:\MySqlConnector\MySql.Data\Provider\obj\Debug\MySql.Data.dll' -- 'The key container name 'ConnectorNet' does not exist' MySql.Data

Author: Mrinmay Paul07 Oct 2010 Member Level: Gold   Points : 1

Hi Diane,

Here is the download link where you can download the installer, but first you have to register.
http://www.mysql.com/downloads/mirror.php?id=393676



cheers
Paul

Author: Mrinmay Paul08 Oct 2010 Member Level: Gold   Points : 1

Hi,

If you have the source and when you compile it gives an error:
Error 2 Cryptographic failure while signing assembly 'C:\MySqlConnector\MySql.Data\Provider\obj\Debug\MySql.Data.dll' -- 'The key container name 'ConnectorNet' does not exist' MySql.Data


This error is raised because the signing of assembly is not done.
To rectify this error
1. open the project file For eg. "MySql.Data"
2. Click the Project Tab in menu bar of Visual Studio
3. You will find "MySql.Data Properties", click on it.
4. A property window will open up.
5. Click on "sining" tab.
6. Check on the "Sign the assembly" CheckBox
7. Choose a Strong name.
8. If you donot have one click on ""
9. "Create Strong Name" window will pop up.
9. Give a name to "Key file_name"
10. If you want it to be password protected (optional), Enter the passwords. Click "Ok"
If you don't want password protected un-check the "Protect my key file with a password". Click "Ok"
11. Now build it.

Now the build wont give error

Cheers
Paul

Author: Vaishali Jain04 Apr 2011 Member Level: Gold   Points : 1

.msi file is there but you need to click the second download button to download .msi file to install my connector for .net

Author: Priya K17 Jun 2011 Member Level: Silver   Points : 1

We can also make use of


System.Data.Odbc


and we can use the connection string like



connectionString="Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=db;User=usr;Password=pwd;"


so that with out using reference we can make use of 'ODBC' of .net

Guest Author: Ogbonda22 Jul 2012

After adding the connector and adding mysql.data.dll to my project and adding using using MySql.Data
using MySql.Data.MySqlClient on the cs

my sql is insyde xampp.....

I added this membership provider

when trying to compile it..it showing me error...and if i go to the asp.net config file it will show error referring me to config file ...kindly assist me...
thanks



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: