PDA

Click to See Complete Forum and Search --> : [RESOLVED] Connect to MySQL with C#


Arc
Jul 6th, 2007, 06:36 PM
Hey guys, I have done some searching and found a couple things on this subject but I have not found a full example.

I have never programed with C# or any .net languages so I am pretty lost here. I am a web developer and I use php exclusively so i do understand the concepts, but I would like a working example if anyone can provide it.

The MySQL DB is on a seperate server and this application will be a desktop app not web based.

I looked at connectionstrings.com but i am not sure If I should be using MyODBC or OleDB or ADO or what. And I am not sure what to put in the "using" area of the app or what I need to download or anything.

Also, the easier the setup is for the user who installs the app the better. I don't want them to have to download any special drivers to get this to work (But I assume the distribution package will include all necesary components).

I was reading something on the MYODBC page that has a certain liscence with it...Since this will be a commercial app, I would rather not deal with liscences and such.


I appreciate any input you can give me on this.

Thanks!:wave:

Ohh btw, I am using VS 2005 Standard if that matters.

jmcilhinney
Jul 6th, 2007, 08:10 PM
If you go back to www.connectionstrings.com and click on the MySQL link you'll see connection string formats for various ADO.NET providers. There is one named "Connector/NET" and I would recommend using that. It is a free, MySQL-specific provider available from the MySQL Web site and there's a link to the download under the connection string format at www.connectionstrings.com. You download and install that, then add a reference to your project. You can then use it as you would any other ADO.NET provider that comes with the Framework.

Arc
Jul 6th, 2007, 08:18 PM
Are you talking about MySQLDirect.Net? That is the only one I could find on there. It says it is a free for 30 days then you have to register or something..

Hrmm

penagate
Jul 6th, 2007, 08:48 PM
http://dev.mysql.com/downloads/connector/net/5.0.html

Arc
Jul 7th, 2007, 01:39 AM
"NOTE: By downloading the software from this page, you acknowledge that the software available from here is licensed under the GPL. We advise that you review the GPL before downloading.

If you need commercial, non-GPL, licenses, you can order them online."

This is going to be a commercial app. Isn't there something I can use that is built into VS2005 that I don't have to buy a license for?

arg...

Arc
Jul 7th, 2007, 07:26 PM
Ok, so I assume that I have to use a 3rd party driver to do this right? And I have to pay hundreds of dollars to connect to a MySQL DB?

I have my code working with the driver specified above..but you would think VS2005 would come with a driver that does it for free....As in pre-paid, by buying the VS software.

I am seriously unhappy about this....:cool:

Thanks for pointing me in the right direction anyway.

jmcilhinney
Jul 8th, 2007, 10:43 PM
Microsoft cannot be held responsible for providing an ADO.NET connector specifically for every possible database. You can connect to any OLEDB data source using System.Data.OleDb, but I'm not sure that MySQL have an OLEDB provider any more. You can connect to any ODBC data source using System.Data.Odbc. If you can acquire an ODBC driver for MySQL then you can use that.

JenniferBabe
Jul 9th, 2007, 11:59 AM
if you're using MySql 5.0, simply download the MySql Connector net 5.0.7 which is available on MySql site for free.

After simply build a class to do you reading and writing operations.

After installing the connector, you simply need to add the reference to the following DLL: MySql.Data.dll

In your program, you need to have the following header: using MySql.Data.MySqlClient;

And after that, everything else is simple. Use the MySqlCommand and MySqlDataReader objects to build your class and then reuse it repeatedly.

Hope this helps,
Jennifer.

P.S. from ontop of my head, I bellieve the driver for MySql is open-source.

Arc
Jul 9th, 2007, 10:29 PM
Thanks for the input guys.