Azure网站有时无法连接到SQL Azure数据库 [英] Azure website sometimes can't connect to SQL Azure database

查看:90
本文介绍了Azure网站有时无法连接到SQL Azure数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been testing a website in Azure for about a month (Free trial), and now I've subscribed to pay-as-you-go. When I was on the free trial, I had absolutely no connectivity issues. Now I've deployed again to a fresh website created on the pay-as-you-go subscription with the same settings (scaling mode etc.) as the previous one. However, now when I navigate to my site, it sometimes fails to connect to my database:

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

我尝试刷新页面并连接.几分钟后,当我再次尝试时,有时会再次遇到相同的错误,但有时却不会.在免费试用模式下,我从未遇到任何连接问题.为什么会发生?如何预防此问题?

I try to refresh the page and it connects. After a few minutes, when I try again, I sometimes get the same error again, but sometimes not. I never had a single connectivity issue in the free trial mode. Why does it happend and how can I prevent this problem?

推荐答案

在云环境中可能会出现短暂错误.假设数据库调用失败,如果您在几毫秒后重试,则该调用现在可以正常工作.为了避免这些错误,您需要实现重试逻辑.如果您使用Entity Framework 6,则很幸运,因为它已在以下环境中生成: http://msdn.microsoft.com/zh-CN/data/dn456835 以下是有关如何实现此功能的快速视频: http://www.azurerocks.com/0_oaw-merMw

Transient errors are expected in a cloud environment. Let's say that a database call fails, if you retry a few milliseconds later, that same call would now work. To shield you from these errors, you need to implement a retry logic. If you use Entity Framework 6, you're in luck since it's baked in: http://msdn.microsoft.com/en-US/data/dn456835 Here's a quick video on how to implement this: http://www.azurerocks.com/0_oaw-merMw

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

You can also use the Enterprise Library Transient Fault Handling Application Block: http://msdn.microsoft.com/en-us/library/hh680934(v=pandp.50).aspx

这篇关于Azure网站有时无法连接到SQL Azure数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆