我有 Mysql 数据库连接到 .NET MVC。当我连接远程时,它有时工作正常,有时我收到此错误消息:
MySql.Data.MySqlClient.MySqlException (0x80004005): Authentication to host 'ServerName' for user 'UserName' using method 'mysql_native_password' failed with message: Reading from the stream has failed. ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Reading from the stream has failed. ---> System.IO.IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the
请问我该如何进行身份验证?有什么解决办法吗?
最佳答案
当数据库发生某种死锁时,这是一个常见的错误,更常见的是连接打开了很长时间并在数据库端关闭,即使它仍在您的 Web 应用程序中使用。
在我的代码中,我使用了 Microsoft 的建议,即在失败时重试数据库命令。链接在这里:http://social.technet.microsoft.com/wiki/contents/articles/4235.retry-logic-for-transient-failures-in-windows-azure-sql-database.aspx其他使用 RetryPolicy 的非 Azure 问题也存在类似情况。
这在一个简单的(在我的例子中是 Azure)示例中意味着:
private static RetryPolicy<SqlAzureTransientErrorDetectionStrategy> retryPolicy = new RetryPolicy<SqlAzureTransientErrorDetectionStrategy>(new Incremental(3, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)));
// Inside your database function
retryPolicy.ExecuteAction(() =>
{
db.ExecuteStoredProc("procRecordMetric", cmd);
});
关于mysql - 认证 mysql 到 .Net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27106213/