SQL连接等待尽管3秒15秒的连接字符串超时 [英] Sql connection waits 15 seconds despite 3 seconds timeout in connection string

查看:1255
本文介绍了SQL连接等待尽管3秒15秒的连接字符串超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Microsoft SQL 2008服务器在本地网络网站。有时,SQL Server计算机重新启动,因此网站无法连接到数据库。如果机器运行起来,它的将会的快速响应。如果它是向下,是否没有必要等待15秒。 3秒都OK了。

I have a website using Microsoft SQL 2008 server over local network. Sometimes, SQL server machine is rebooted, and so the website fails to connect to the database. If the machine is up and running, it will respond fast. If it's down, there is no need to wait for 15 seconds. 3 seconds are ok.

我要显示表歉意在网站上,当数据库无法访问,并希望做快。但设置连接超时= 3连接字符串似乎有没有影响。该页面花费22秒扔的SQLException SqlConnection.Open()之前的等待时间;

I want to display apologizes on the website when the database is not reachable, and want to do it fast. But setting Connection Timeout=3 in connection string seems having no effect. The page spends 22 seconds to wait before throwing SqlException on SqlConnection.Open();.

这有什么错呢?但愿这是一个隐藏的配置将覆盖超时?

What's wrong with it? May it be a hidden configuration which overrides the timeout?

目前,我的连接字符串

Data Source=...;
Initial Catalog=...;
Integrated Security=True;
Connection Timeout=3

如果我将它设置为 .. ; ConnectionTimeout = 3 (无空格),

If I set it to ...;ConnectionTimeout=3 (without space),

System.ArgumentException: Keyword not supported: 'connectiontimeout'.



被抛出(怪,的 MSDN文档表明我们可以用两个字符串)。

is thrown (strange, MSDN documentation indicates that we can use both strings).

推荐答案

有一个超时的网络硬件报告的连接超时的网络驱动程序,再通知等待网络IO的程序之前。您可以通过telnet服务器名1433(假设你的SQL Server正在侦听端口1433)验证传输层的超时。

There is a timeout before the networking hardware reports connection timeout to the network drivers, which in turn notifies the programs waiting for network IO. You can verify transport layer timeouts via telnet servername 1433 (assuming your sql server is listening on port 1433).

不过3秒钟的时间太短了进程初始化网络的API(假设你的web应用程序是在自己的应用程序池),发送请求并等待硬件超时。更新BIOS /固件/驱动程序可能不会缩短响应时间那么多。

But 3 seconds is way too short for a process to initialize the network APIs (assuming your web app is in its own application pool), send request and wait for the hardware to timeout. Updating BIOS/firmware/driver probably won't reduce the response time that much.

这将是更好的异步进行连接。我不建议使用EndInvoke会结束异步调用的倒霉用户可能仍然需要等待3秒,充分看到任何反应,当数据库关闭。也许一个Ajax调用比较好。如果你有大量的用户不断冲击你的网站,你可能要缓存的连接检查的结果和意义给用户的方式对其进行更新。

It would be better to carry out the connection asynchronously. i do not suggest using EndInvoke to end the asynchronous call as unlucky users may still need to wait 3 full seconds to see any response when the database is down. Maybe an Ajax call is better. If you have a lot of users constantly hitting your web site, you may want to cache the result of connectivity checking and update it in a manner meaningful to your users.

这篇关于SQL连接等待尽管3秒15秒的连接字符串超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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