2016-12-13 24 views
-1

(C#の)どのようにMySQLに接続しますか? MySQLへの接続方法

サーバー:?

ローカルホストUNIXソケット経由

マイコード:

public void Connect() 
{ 
    server = "91.196.48.243"; 
    database = "w554_users"; 
    port = "3306"; 
    uid = "name"; 
    password = "password"; 

    myConnectionString = "Server=" + server + ";" + "Port=" + port + ";" + "Database=" + 
    database + ";" + "Uid=" + uid + ";" + "Pwd=" + password + ";"; 
    conn = new MySqlConnection(myConnectionString); 

    conn.Open(); 
} 

そして、私は、このエラーを与える:

An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll

Additional information: Host '188.47.8.212' is not allowed to connect to this MySQL server

============================================== ===========================

phpmyadminの

Ip: 91.196.48.243

に私がログインした場合=====

============

は私がポート(2222)に変更

エラー:

An unhandled exception of type 'System.TimeoutException' occurred in MySql.Data.dll

Additional information: Timeout in IO operation

+0

を使用すると、リモートでこれはNamedPipesのあるデシベル –

+0

にアクセスするには、この特定のIP、ユーザ名とパスワードへのアクセスを許可する必要がありますあなたがIPアドレスに基づいてアクセスするように構成されたデータベースはまた、あなたの現在の場所からそのサーバーにpingを実行することができていることを確認する必要があるように/ IPの問題のpingが聞こえる..私はまた、セットアップに.configファイルを使用してになり、あなたのDB接続等.. – MethodMan

答えて

2

あなたのIP doesntのは、MySQLのサーバにアクセスする権限を持っているように見えます。

Additional information: Host '188.47.8.212' is not allowed to connect to this MySQL server

あなたDrirectAdminにこのソリューションをお試しください:mysqlの中

If you have a MySQL database with your hosting account and need to connect to it from your home computer, or another web server, you'll need to add a remote "Access Host" to your database to allow the connection in. Go to:

User Level -> MySQL Management -> databasename -> Add Access Host 

You can either add the IP of the remote connecting box, or just use: %

to allow any IP (if you're unsure of the remote IP, or if it may change)

Note that the correct login/password is still required, the Access Host is just another layer of security.

Also make sure that port 3306 is open in your firewall on the DirectAdmin box, so the remote box can connect.

Connect to your MySQL database from a remote connection

0

あなたのMYSQLサーバは、そのIPからの着信接続を許可しません。サーバからの接続を許可してください。