Friday, April 8, 2011

How to setup MySQL connector with Visual Studio

Hey there, this post is to just help out everyone out there (and at the same time logging down what I've done, in case I need to refer to it in the future) who is struggling with getting the MySQL connector working with ASP.NET.

Now let's get our hands dirty.

The things that you'll really really need:

1) Microsoft Visual Studios, either the Professional/Premium or whatever edition, so long as it's not the free edition. Yes you've heard me, not the FREE or Express edition.

The issue is that the Express (FREE yes I must emphasize this many times. Not all freelancers can afford to buy a new software for every little single project they handle) where was I?

Oh yes the Express edition is unable to load 3rd party plugins/connectors. And MySQL is 3rd party.

At this point in time, you have to make a painful decision before continuing on this post.
Pay for a professional VS copy, or switch to the proprietary MS SQL server.

As for me, I'm currently using the Trial version (good for 30 days) to finish my project.
If you only have a short project to handle, go ahead, get the Trial version.

2) MySQL connector. Go ahead and Google and download it. Install it.

3) After installation and having your MySQL server set up, you need to "Add A Reference". Yep, this step has confounded me for a bit. Basically when you are in Visual Studios, under the Menu Bar, select "View" and then "Solution Explorer". And in the "Solution Explorer", right click on "Reference" and add a new reference.

The MySQL connector should be in the .NET section, look for MySQL.Data.
Not sure what's the difference between 2.0x and 4.0x but I'm using the 4.0x reference and it works for me.

Here's the link to the MySQL Connector PDF guide by MySQL if you need it: MySQL Connector PDF

And have fun for your project!