Sign in to follow this  

[.net] .Net + MySQL, anyone?

This topic is 4049 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

anyone know how to get MySQl working under a .Net app? Since .Net doesn't have native support for MySQL I was thinking i could use ODBC. my MySQL database is remotely accessible on freesql.org when i attempt to open a connection i get an exception. something about odbc driver. am i trying the impossible here?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You might want to look in to ADO.NET if you are using .NET for this. I found a few tutorials that would connect to my local server and get some data, but decided to just buy a book on the subject.

Share this post


Link to post
Share on other sites
im about to try out that link that was posted. incidentally though, i did try that search query. i've tried many different combinations. no real luck though.

as for the ado.net, that is exactly what im using.
ado.net supports SQL, OLE, ODBC, and Oracle. MySQL is different from these, but like i said, i tried ODBC, a generic approach to generic database connections.

Share this post


Link to post
Share on other sites
"There are a number of fully managed .NET providers available to help MySQL users develop applications in the .NET environment.

Two popular choices are:

1. ByteFX.Data
2. CoreLabs"

i just downloaded CoreLabs. this is better than what i'd expected! thanks very much.

Share this post


Link to post
Share on other sites
Quote:
Original post by Thevenin
Download the "MySQL Connector Net 1.0.7" from the MySQL website. It is what I use, and I'm finding it to be quite beginner friendly.


thats the way to go imho. basically its a simple library dll, you have to distribute with your app. you get the mySQL namespace with all the familiar ADO objects implemented having mySQL prefixes instead of sql/odbc/lodb/other...

Share this post


Link to post
Share on other sites
Absolutely. You should be able to use almost any database with .NET. If the database has at least an ODBC interface, you can use .NET to connect to it. ODBC is not the best choice though, as it's very generic, and has no optimizations for specific databases. It is best to use a .NET connecter for the database if it is available. There is one provided by MySQL.

Incidentally, I wrote about this a while ago. I'd suggest taking a look on my website, under ASP.NET (applies to .NET in general), for more info.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I accessed a MySQL DB from C# about 3 yrs ago. It wasn't hard but my memory is fuzzy...

I don't think MySQL had a .NET interface then. Apparently from the above posts, now it does.

When you tried ODBC and failed, I'm guessing you neglected to install MySQL's client-side ODBC driver. I believe, for any DB which supports ODBC, you have to install that DB's client-side ODBC driver for it to work.

Share this post


Link to post
Share on other sites
Most friendly solution as previously described would be:
MySQL Connector / NET 1.0 - [Direct Download]

Most generic would be:
MySQL Connector/ODBC

I have to admit that at first ADO.NET looks a bit confusing, though its very powerfull and contrary MySQL .NET Connector this is cross-platform. :) Ok, I might be wrong about .NET part possibly - they provide source code and it might compile under Mono too. Not really sure about that though.

By the way there are many MySQL ADO.NET providers. This might interest you.

Share this post


Link to post
Share on other sites
fellas, i'm using the connector for MySQL by CoreLabs. it works like a charm.
It intergrated perfectly with ado.net. It's now another database type that i can choose from in addition to odbc and sql...etc.

Share this post


Link to post
Share on other sites
Thanks for the heads up Rob.

I have programmed a small application to load content from a database and then write updates / etc. back to it using C#/.NET 2.0 and I used the MySQL ODBC Connector... I picked it because it is extremely lightweight and syncs well with what I do in PHP. That is MySQL commands are identical and only the class names and how you run commands changes a bit. Here is some sample source abstracted from the program. I could post the full source, but it might be confusing as I am also using a prototype runtime loaded GUI. It makes a lot of the commands really abstract...


string _connStr = "DRIVER={MySQL ODBC 3.51 Driver};" +
"SERVER=" + tbServer.Text + ";" +
"DATABASE=" + tbDatabase.Text + ";" +
"UID=" + tbUser.Text + ";" +
"PASSWORD=" + tbPass.Text + ";" +
"OPTION=3";

frm.SQLConnection = new OdbcConnection(_connStr);

Share this post


Link to post
Share on other sites
You probably want to use a managed provider NOT anything that involves ODBC or Ole DB.

A managed provider means your code will be 100% CLR and thus more reliable and possibly perform better.

For me the reliability is definitely the thing. Fewer layers is also always better.

Mark

Share this post


Link to post
Share on other sites

This topic is 4049 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this