0

I am just creating a new program that will connect to mysql.

I just do it but the problem is localhost. I want to use my cpanel ip ( my web address ip ) in Server instead of localhost.

My code is this

    server = "37.187......";
    database = "mydbname";
    uid = "mydbid";
    password = "mydbpass";
    string connectionString;
    connectionString = "SERVER=" + server + ";" + "DATABASE=" +
    database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";

    connection = new MySqlConnection(connectionString);
    MessageBox.Show("CONNECT");

when i run this code it cant be connect with mysql but when i use server = "localhost"; it runs easily.

Any solution ?

Gaurav Deochakke
  • 2,265
  • 2
  • 21
  • 26
Hammad
  • 173
  • 1
  • 1
  • 6
  • 2
    Your mysql instance may have security configured to only allow localhost connections. Which is a good thing anyway. You shouldn't use external IP as this opens a security risk and adds maintenance overhead, especially if you have ability to use localhost. – oleksii May 26 '14 at 10:13
  • If I understand correctly, you're trying to use your *external* IP address, from inside of your network. This will not do (your computer does not know anything about the external IP, and it's meaningless from the inside, because all devices inside the network share the external IP). You may use your internal IP address (which is probably something like `10.0.0...` or `192.168....`), or, if you have static external IP, and you configured your router port forwarding, you can refer to that address from the *outside* of your network. – Shlomi Borovitz May 26 '14 at 10:13
  • Thank you Both . I am Creating a Login Form in CSHARP where i want to user to login with id and password which is on my website mysqldatabase – Hammad May 26 '14 at 10:15
  • You can't do that and you don't want to do that. You don't want to expose your database server to the internet; you will be hacked by brute force. Create a webservice on your webserver that exposes the data you want to expose. See [C# Use/connect to MySQL database in webhost (One.com)](http://stackoverflow.com/questions/18507924/c-sharp-use-connect-to-mysql-database-in-webhost-one-com), [i can't access to mysql database from c#](http://stackoverflow.com/questions/17474632/i-cant-access-to-mysql-database-from-c-sharp) and so on, try to search. – CodeCaster May 26 '14 at 10:23

0 Answers0