asp.net - Azure网站有时无法连接到SQL Azure数据库

标签 asp.net azure azure-sql-database

我已经在 Azure 中测试了一个网站大约一个月(免费试用),现在我已经订阅了按需付费。当我进行免费试用时,我完全没有遇到连接问题。现在,我再次部署到一个在即用即付订阅上创建的新网站,其设置(缩放模式等)与前一个网站相同。但是,现在当我导航到我的网站时,它有时无法连接到我的数据库:

Server Error in '/' Application.
A connection attempt failed because the connected party did not properly respond after
a period of time, or established connection failed because connected host has failed to
respond
Description: An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the error and where
it originated in the code.

Exception Details: System.ComponentModel.Win32Exception: A connection attempt failed 
because the connected party did not properly respond after a period of time, or
established connection failed because connected host has failed to respond

Source Error:

An unhandled exception was generated during the execution of the current web request.
Information regarding the origin and location of the exception can be identified using
the exception stack trace below.

Stack Trace:


[Win32Exception (0x80004005): A connection attempt failed because the connected party 
did not properly respond after a period of time, or established connection failed 
because connected host has failed to respond]

[SqlException (0x80131904): A network-related or instance-specific error occurred 
while establishing a connection to SQL Server. The server was not found or was not 
accessible. Verify that the instance name is correct and that SQL Server is configured
to allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt
failed because the connected party did not properly respond after a period of time, or
established connection failed because connected host has failed to respond.)

我尝试刷新页面,它已连接。几分钟后,当我再次尝试时,有时会再次出现相同的错误,但有时不会。在免费试用模式下我从未遇到过任何连接问题。为什么会发生这种情况以及如何防止这个问题?

最佳答案

云环境中预计会出现暂时性错误。假设数据库调用失败,如果您在几毫秒后重试,那么相同的调用现在可以工作。为了避免这些错误,您需要实现重试逻辑。如果您使用 Entity Framework 6,那么您很幸运,因为它内置于:http://msdn.microsoft.com/en-US/data/dn456835 以下是有关如何实现此功能的快速视频:http://www.azurerocks.com/0_oaw-merMw

您还可以使用企业库 transient 故障处理应用程序 block :http://msdn.microsoft.com/en-us/library/hh680934(v=pandp.50).aspx

关于asp.net - Azure网站有时无法连接到SQL Azure数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23290720/

相关文章:

c# - 在服务器上均匀上传文件

c# - 如何在代码隐藏中使用javascript确认方法

azure - 减少从 UWP 应用发送的遥测流量

asp.net-mvc - 如何在 azure 中创建 API 运行状况检查?

azure - Azure SQL DB 与 Azure 搜索的自动索引/同步如何工作?

performance - 对非常大的 SQL 表进行简单的 UPDATE 查询

c# - 在 ASP.NET 网站中使用静态成员是不好的做法吗?

javascript - 单击后如何禁用按钮以避免多次发布请求?

azure - 如何引用存储和 key 保管库更新 Azure 函数应用程序的应用程序设置? - 带有二头肌和模块

reporting-services - 计划在不使用时在 Azure 上的 SQL 报告中禁用/启用