Thursday, January 10, 2013

First attempt to connect to mySql database with ASP.NET

After a few day researching and trying, finally I've successfully connect to mySql database with ASP.NET.
I really gotta write down how to do so, otherwise I'll surely forget the steps even in near future.

I have WAMP server installed, (learn how to set up WAMP server here) at first I was working with the mysql already installed with WAMP.
I tried to connect to the database, but failed to do so, I always got "ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified" when I was trying to call Connection.Open().
I have been searching around, but couldn't find the solution yet, and I suspected it was something wrong with my mysql setting, then I decided to install mysql separately.

These are how it helped me to work:

1. First, I downloaded MySQL Community Server 5.5.29, the latest version, zip edition, but I couldn't understand how it worked.
Then I clicked on "Looking for previous GA versions?", downloaded & installed MySQL Community Server 5.1.67.
I just revisited the page now, and now only I found there is a recommended download - MySQL Installer 5.5 for Windows (All MySQL Products - including MySQL server, connectors, Workbench, etc), perhaps I should get this.

2. Then, I got the MySQL Workbench, which is a GUI tool, to help me easily work with the database.
After setting all these, I still get the "Data source name not found" error.

3.Finally, I found this - Setting up MySQL for use through ODBC. This really saved me! And I managed to connect to mysql database successfully!

This is the connection string I use:
DRIVER={MySQL ODBC 5.1 Driver};SERVER=localhost;PORT=3306;DATABASE=test;UID=root;PWD=;

No comments:

Post a Comment