How to connect c# to remote mysql database

In this quick tutorial I’m going to show you how you can connect your c# application to a remote mysql database. There’s no additional coding involve in this tutorial all you need to do is to configure your connection string a little bit and configure the privileges on your mysql database.

 

Requirements

  • phpmyadmin

 

Privileges

First you have to access your mysql database using phpmyadmin.

http://localhost:8080/phpmyadmin/

Click on the privileges tab then change the host to Any host.

image

 

Connection String

Finally you just have to change the server you’re connecting to. This time its not localhost since you’re not connecting to the database on your local computer.

string con_string = "Server=192.168.218.10;

Database=cake_beginner;Uid=root;Pwd=1234";

In the example above I used the internal ip address. If you don’t know your internal ip address. Just go to cmd and type ipconfig/all and copy the ip version 4 preferred address. Well that’s just internal ip address, which means that only the people who are inside your home network can access. If you want to connect to a remote mysql database you have to determine your external ip address, you can do so by going to cmyip.com. But remember that the ip address of the computer you’re trying to access should be static so that you won’t need to change your connection string every time you need to connect to the remote mysql database.

I have written a tutorial before on how to connect to a remote computer. You might want to read it if you don’t know how to configure your router to make remote access possible.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s