2014-03-06 82 views
0
protected void Button1_Click(object sender, EventArgs e) 
{ 
    try 
    { 
     string MyConString = "SERVER=http://10.54.3.208:8080/Ager/person;" + "DATABASE=agero;" + "UID=root;" + "PASSWORD=root;"; 
     MySqlConnection con = new MySqlConnection(MyConString); 
     //MySqlConnection command = con.CreateCommand(); 
     con.Open(); 
     string s = "select * from boopathi where STU_ID [email protected] and STU_PWD [email protected]"; 
     MySqlCommand cmd = new MySqlCommand(s, con); 
     cmd.Parameters.AddWithValue("@sid", TextBox1.Text.ToString()); 
     cmd.Parameters.AddWithValue("@pwd", TextBox2.Text.ToString()); 
     cmd.ExecuteNonQuery(); 
     MySqlDataReader dr = cmd.ExecuteReader(); 
     while (dr.Read()) 
     { 
      if (dr.HasRows == true) 
      { 
       Server.Transfer("WebForm1.aspx"); 
      } 
     }  
     //close connection 
     con.Close(); 

    } 
    catch (Exception ex) 
    { 
     Response.Write("An error occured: " + ex.Message); 
    } 
} 

在本地主機上它工作的很完美。一旦我設置了遠程鏈接而不是本地主機。它不再連接。我越來越喜歡Unable to connect to any of the specified MySQL hosts.如何使用mysql在asp.net中連接遠程數據庫?

+0

我猜想端口3306被阻塞在你的網絡路徑中。什麼是提出的例外? – rene

+0

我得到「無法連接到任何指定的MySQL主機」。 – user2995210

+0

將其編輯到您的問題中,這非常相關。你已經檢查過端口3306是否被阻塞? – rene

回答

0

嘗試: -

MySqlConnection c = new MySqlConnection("server=10.54.3.208; database=agero; uid=root; pwd=root"); 

OR

string MyConString = "SERVER=10.54.3.208;" + "DATABASE=agero;" + "UID=root;" + "Pwd=root;"; 

參考,因爲我希望它可以幫助您瞭解更多信息MySQL Connector

此鏈接。

相關問題