我正在尝试从Azure网站中部署的ASP.NET MVC4 Web应用程序(默认“Internet”)连接到现有的MySQL数据库,该数据库不在Azure上托管。我尽可能简化以说明问题:
1)我通过Nuget
添加到我的MVC应用程序MySql.Data和MySql.Web
2)我在默认的HomeController中在About()方法中编写了以下丑陋的代码:
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网站的那一刻,如果失败了。产生的Trace如下:
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 :(得分:0)
从我收集的内容来看,问题是MySQL默认使用反向DNS查找,目前Azure不支持这种查找:
Reverse DNS lookup on Windows Azure? Setting up reverse dns on windows azure?
看起来有可能turn off MySQL reverse DNS lookup,但我还没有尝试过(现有的数据库不在我的控制范围内)。