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

5

我在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.)

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


你是否使用或实现了某种重试逻辑? - CSharpRocks
@CSharpRocks 不,我该怎么办? - Can Poyrazoğlu
1个回答

4
在云环境中,短暂错误是正常的。比如说,数据库调用失败了,如果你在几毫秒后重试,同样的调用现在会成功。为了保护你免受这些错误的影响,你需要实现重试逻辑。如果你使用的是Entity Framework 6,你很幸运,因为它已经内置了:http://msdn.microsoft.com/en-US/data/dn456835。以下是一个快速实现的视频:http://www.azurerocks.com/0_oaw-merMw
你也可以使用Enterprise Library Transient Fault Handling Application Block:http://msdn.microsoft.com/en-us/library/hh680934(v=pandp.50).aspx

2
我会看一下。你有什么想法,为什么这种情况在一个月内从未发生过,但在我转到付费订阅后开始发生? - Can Poyrazoğlu
我猜这是因为在试用订阅中,资源以更高的优先级提供,以便新手有机会尝试所有功能并集中精力于功能本身。 转到付费订阅服务后,服务质量取决于您选择的服务计划(较小-更便宜的实例大小意味着带宽较小)。 这是我个人对所有这些工作方式的看法。 - Konstantin Isaev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接