与 SQL Server 连接的初始连接很慢.为什么? [英] Initial connection to SQL Server Connection Is Slow. Why?
问题描述
我遇到了在两个站点上安装 C# 应用程序的情况,其中到 SQL Server 的初始连接非常慢.我编写了一个测试应用程序来验证减速发生的位置,它发生在第一个 SQLConnection.Open 语句上.通过命名管道与服务器建立连接大约需要 41 秒.我们认为这可能是 DNS 问题,但使用 TCP/IP 连接也一样慢.初始连接建立后,连接被池化,应用程序正常响应.工作站和服务器都是运行 Windows 7 Pro、Core 2 Duo 3.16 Ghz 和 4 g 内存的不错的机器.我确实在微软论坛上找到了以下文章:
I have run into a situation with a C# application installed at two sites where the initial connection to SQL Server is extremely slow. I wrote a test application to verify where the slowdown occurs and it is on the first SQLConnection.Open statement. It was taking about 41 seconds to establish a connection to the server via named pipes. We thought it might be a DNS issue but its just as slow using a TCP/IP connection. After the initial connection is made the connection is pooled and the application responds normally. Both the workstation and the server are decent machines running Windows 7 Pro, Core 2 Duo 3.16 Ghz with 4 gig of Ram. I did find the following article on a microsoft forum:
关闭 LLMNR 协议确实将初始连接时间缩短了大约一半到 21 秒.但是,这仍然需要很长时间才能与 SQL Server 建立初始连接.唯一与我们的规范略有不同的是,在这种情况下,DNS 是通过路由器而不是实际服务器完成的.到目前为止,这种情况只发生在两个地方,其他地方都没有问题.任何帮助将不胜感激.
Turning off the LLMNR protocol did cut the initial connection time in about half to 21 seconds. However, this is still a long time to get an initial connection to SQL Server. The only things slightly different from our norm is that DNS in this case is done thru a router and not an actual server. This has occurred at only two places so far, others run with no issues. Any help would be appreciated.
谢谢,丹尼斯
推荐答案
在连接字符串上的服务器前面,添加np:
In front of the server on the connection string, add np:
这变成了 Server=np:serverinstance
并强制命名管道而不是 TCP 的默认值.
This becomes Server=np:serverinstance
and forces the Named Pipes instead of the default of TCP.
我可能会更改优先级以在 TCP 之前使用命名管道......但我不想在服务器上弄乱它.
I could of probably changed the priority to use Named Pipes before TCP... but I did not want to mess with that on the server.
这篇关于与 SQL Server 连接的初始连接很慢.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!