Azure网站有时无法连接到SQL Azure数据库

时间:2014-04-25 10:38:07

标签: 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.)

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

1 个答案:

答案 0 :(得分:4)

云环境中预计会出现瞬态错误。假设数据库调用失败,如果您在几毫秒后重试,则现在可以使用相同的调用。为了保护您免受这些错误的影响,您需要实现重试逻辑。如果您使用实体框架6,那么您很幸运,因为它已经出现了:http://msdn.microsoft.com/en-US/data/dn456835 以下是有关如何实现此问题的快速视频:http://www.azurerocks.com/0_oaw-merMw

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