2013-07-31 26 views
1

我試圖從ASP.NET MVC4 Web應用程序(默認「Internet」)連接到現有MySQL數據庫,該數據庫未託管在Azure上,部署在Azure網站。我簡化儘可能來說明問題:通過的NuGet
2)未能從Azure網站上的MVC4應用程序連接到MySQL

1)我加入到我的MVC應用程序MySql.Data和MySql.Web我寫在默認的HomeController以下醜陋的代碼,在關於()方法:

public ActionResult About() 
{ 
    try 
    { 
     ViewBag.Message = "Your app description page."; 

     Trace.TraceInformation("Connection String"); 
     var connStr = 
      "server=blah.blah.com;user=someone;database=somedatabase;port=3306;password=password;"; 

     Trace.TraceInformation("Connection"); 
     var connection = new MySqlConnection(connStr); 

     Trace.TraceInformation("Open Connection"); 
     connection.Open(); 

     Trace.TraceInformation("Close Connection"); 
     connection.Close(); 

     return View(); 
    } 
    catch (Exception ex) 
    { 
     Trace.TraceError("{0}/{1}/{2}", ex.Message, ex.StackTrace, ex.TargetSite); 
     throw; 
    } 
} 

當我調試(我沒有問題,檢索數據要麼),但我發佈到Azure的網站的那一刻,如果悲慘的失敗了此運行沒有我的本地機器上的毛刺。產生的痕跡如下:

2013-07-31T03:05:02 PID[20636] Information Connection String 
2013-07-31T03:05:02 PID[20636] Information Connection 
2013-07-31T03:05:02 PID[20636] Information Open Connection 
2013-07-31T03:05:09 PID[20636] Error  Can't get hostname for your address 
2013-07-31T03:05:09 PID[20636] Error  Can't get hostname for your address/ at MySql.Data.MySqlClient.MySqlStream.ReadPacket() 
    at MySql.Data.MySqlClient.NativeDriver.Open() 
    at MySql.Data.MySqlClient.Driver.Open() 
    at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) 
    at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() 
    at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() 
    at MySql.Data.MySqlClient.MySqlPool.GetConnection() 
    at MySql.Data.MySqlClient.MySqlConnection.Open() 
    at MvcTest.Controllers.HomeController.About()/MySql.Data.MySqlClient.MySqlPacket ReadPacket() 

有人能幫我弄清楚我做錯了什麼嗎?有沒有一個特定的原因爲什麼這將失敗從一個Azure網站,而不是我的本地機器?注意:我的本地機器與MySQL數據庫不在同一個網絡上,或類似的東西。

+0

這只是推測,但它似乎有一個問題,解決您的機器名稱。看看有人遇到同樣問題的長篇帖子http://forum.openoffice.org/en/forum/viewtopic.php?t=41292 – Namphibian

回答