Thomas Sampson

Connecting to MySQL from asp.NET

Leave a comment

To connect to mySQL from .net 2 things are required

odbc .NET connector (available from
mySQL .net adapter (available from MySQL site)

then, in c#


using System.Data.Odbc;

CONNECTION (written from memory as a guide)

string connectionstring=”Driver={mySQL};;Port=3306;Option=131072;Stmt=;Database=my-database;Uid=username;Pwd=password;”;

odbcConnection goconnect = new odbcConnection(connectionstring);
odbcCommand insertsumat=new odbcCommand(“insert into tablename values(‘fred’,17′)”,goconnect);
odbcCommand retrievesumat=new odbcCommand(“select * from users where name like ‘tom'”,goconnect);
odbcDataReader readit=retrievesumat.ExecuteReader();

Thats pretty much it, used in same way as a OleDB connection to an access database, just using a different adaptor (odbc) and a new connection string. Any probs check port matches that of mySQL.


Author: tomtech999

I have recently graduated with a 1st class degree in MComp Games Software Development at Sheffield Hallam University, focusing primarily on application development in C++, with experience in graphics programming, scripting languages, DVCS/VCS and web technology. In my spare time I enjoy Drumming, Reading and Snowboarding!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s