How do i connect a windows C# application to a remote Mysql database?

Question by bigkid: How do i connect a windows C# application to a remote Mysql database?
I’m currently connected to a local Microsoft SQL server. I’m new to windows programming and i need the code snippets to connect my windows C# application to a remote Mysql database. I have a website which is connected to my web host’s Mysql database. I want to be able to connect my windows C# app. to that same data base. Need your expert advice. By the way, I’m using visual studio.

Best answer:

Answer by wallmeister
It’s the same for a remote database as local. When you set up the data source, just specify the remote server.

Add your own answer in the comments!

No related content found.

Revisions

There are no revisions for this post.

Tags: , , , , ,

One Response to “How do i connect a windows C# application to a remote Mysql database?”

  1. Rott January 18, 2011 at 12:13 AM #

    You need to install the drivers to setup an ODBC connection which can be found here:

    http://www.mysql.com/products/connector/

    After you have the drivers installed, setup your DSN to connect to your remote mysql database. You will likely need to add your ip to the Remote Database Access Hosts depending on how the Mysql server is configured.

    You will then be able to use code as follows (replace the DSN name “test” with the name you provide when creating the DSN):

    using System.Data.Odbc;
    OdbcConnection DbConnection = new OdbcConnection(“DSN=test”);
    DbConnection.Open();

    OdbcCommand DbCommand = DbCommand.CommandText = “SELECT * FROM TABLE”;
    OdbcDataReader DbReader = DbCommand.ExecuteReader();DbConnection.CreateCommand();

Leave a Reply