Results 1 to 9 of 9

Thread: [RESOLVED] Connect to MySQL with C#

  1. #1

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    Resolved [RESOLVED] Connect to MySQL with C#

    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!

    Ohh btw, I am using VS 2005 Standard if that matters.
    Last edited by Arc; Jul 6th, 2007 at 07:56 PM.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Connect to MySQL with C#

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    Re: Connect to MySQL with C#

    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
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

  5. #5

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    Re: Connect to MySQL with C#

    "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...
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  6. #6

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    Re: Connect to MySQL with C#

    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....

    Thanks for pointing me in the right direction anyway.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Connect to MySQL with C#

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: Connect to MySQL with C#

    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.

  9. #9

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    Re: Connect to MySQL with C#

    Thanks for the input guys.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width