与 SQL Server 连接的初始连接速度很慢.为什么?

Initial connection to SQL Server Connection Is Slow. Why?(与 SQL Server 连接的初始连接速度很慢.为什么?)

本文介绍了与 SQL Server 连接的初始连接速度很慢.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了在两个站点上安装了一个 C# 应用程序的情况,其中与 SQL Server 的初始连接非常慢.我编写了一个测试应用程序来验证减速发生的位置以及它在第一个 SQLConnection.Open 语句上.通过命名管道建立与服务器的连接大约需要 41 秒.我们认为这可能是 DNS 问题,但使用 TCP/IP 连接时速度也一样慢.建立初始连接后,连接被池化并且应用程序正常响应.工作站和服务器都是运行 Windows 7 Pro、Core 2 Duo 3.16 Ghz 和 4 gig 内存的不错的机器.我确实在微软论坛上找到了以下文章:

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:

http://social.msdn.microsoft.com/Forums/en/windowscompatibility/thread/f295994c-5812-4e46-8ac9-f05471d4dd54

关闭 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 连接的初始连接速度很慢.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:与 SQL Server 连接的初始连接速度很慢.为什么?

基础教程推荐