mysql - 认证 mysql 到 .Net

标签 mysql asp.net-mvc database

我有 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/

相关文章:

php - 查询顺序不正确

php - 对同一请求使用 mysql GROUP BY 和 ORDER BY

asp.net - ASP.NET 中的 iPhone Web 应用程序开发 - 从哪里开始?

xml - 将表迁移到 Sql XML 字段

Mysql结果包含e+07,如何从结果中转义e+07

MySQL - 外键受同一个表中的主键约束,错误#1452

mysql IN查询问题

asp.net-mvc - Durandal KO 绑定(bind) View 问题

asp.net-mvc - asp mvc : database calls and caching, 引入第四个实体?

没有与数据库紧密耦合并使用存储过程的 PHP 框架?