1. Home
  2. Computing & Technology
  3. C / C++ / C#

How to Use MySQL Database with Visual C# 2008 Express Edition

By , About.com Guide

2 of 4

Working with ODBC

Configure The ODBC Data Source Name
Before you can connect to a database via ODBC you have to setup a DSN which is short for Data Source Name. This is is done the via Control Panel/Administrative Tools/Data Sources (ODBC). You'll see multiple tabs but the first two are the most important. User DSN is just for your apps to use. System DSN is for any application including services on the PC. I prefer System but if its your PC, it doesn't matter which you use unless you ever need to login under a second user account. In that case use System DSN.

Click the Add button and then select the MySQL 3.51 Connector and click finish. This will open up a new Form where you can fill in details of how to connect to your MySQL database. You can see my connection details. You must know your user name/password, the database and then give it a name to use. In my case the name is sirius. If all goes well then the Test Connect button will verify your configuration or tell you what went wrong if it doesn't.

There are two other tabs on the ODBC Connector dialog (Connect Options and Advanced) but unless your database is a bit unusual (as in you are accessing it via SSL or on a different port/socket) or you wish to log sql statements then the 3 sub tabs of flags cover most eventualities.

I suggest you take screen shots (open the config tab, click anywhere on it then hit the PrintScrn button (usually to the right of the F12 key on standard keyboards) then paste that into a document somewhere and keep it safe. You'll need it when you change your PC or reinstall Windows.

On the next page - Hooking up to MySQL

Explore C / C++ / C#
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. C / C++ / C#
  4. C# / C Sharp
  5. How To Do Things in C#
  6. Working with ODBC

©2009 About.com, a part of The New York Times Company.

All rights reserved.