简体   繁体   English

在连接字符串中使用 IP 时查询非常慢 SQL

[英]Very slow SQL query when using IP in connection string

I am having a real big headache with slow SQL query.我对缓慢的 SQL 查询感到非常头疼。 I have two connection string which are as follows:我有两个连接字符串,如下所示:

ConnectString1 = "Driver={SQL Server};Server=MSSQLSERVER5;Database=SchoolMain;Uid=Admin;Pwd=admin101;"

and

ConnectString2 = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=Admin;Password=admin101;Initial Catalog=SchoolMain;Data Source=192.168.1.2,1433"

Both are connecting to a SQL Server database instance on the same system.两者都连接到同一系统上的 SQL 服务器数据库实例。 The first connects using the database instance name, while second connects using IP address (over the internet to the system) and port number.第一个使用数据库实例名称进行连接,而第二个使用 IP 地址(通过 Internet 连接到系统)和端口号进行连接。

The query with ConnectString1 is very first, takes less than 2 seconds to execute while query using ConnectString2 is extremely very slow and most times comes back with timeout expired error.使用ConnectString1的查询是最先执行的,执行时间不到 2 秒,而使用ConnectString2的查询非常慢,并且大多数时候返回超时过期错误。

I have searched everywhere on the internet and still cannot find where the issue is.我在互联网上到处搜索,仍然找不到问题所在。 I read about turning off the LLMNR protocol and adding entries in the hosts file to tackle Reverse DNS, followed the steps but it's still the same as query with ConnectString2 is still very slow.我读到了关于关闭 LLMNR 协议并在主机文件中添加条目以解决反向 DNS 的信息,按照步骤操作,但它仍然与使用ConnectString2的查询仍然很慢一样。

Though when I changed the IP address in ConnectString2 from 192.168.1.2 to 127.0.0.1 , the query works very fast, just exactly as it is with ConnectString1 .虽然当我将ConnectString2中的 IP 地址从192.168.1.2更改为127.0.0.1时,查询的运行速度非常快,就像使用ConnectString1一样。

Is there a way to route all IP address to 127.0.0.1 on the machine?有没有办法将机器上的所有 IP 地址路由到 127.0.0.1 ?

I need ConnectString2 to work query will be pushed over the IP address from other systems outside the LAN.我需要ConnectString2才能工作,查询将从 LAN 外的其他系统推送到 IP 地址。

Note: I am using SQL Server 2008注意:我使用的是 SQL 服务器 2008

Please help.请帮忙。

The main reason this may happen is reverse DNS, meaning the sql needs to translate the IP to a physical address and it takes time.这可能发生的主要原因是反向 DNS,这意味着 sql 需要将 IP 转换为物理地址,这需要时间。

To fix this problem use your host file to add the address to your machine and than use the name given at the host file instead of the IP.要解决此问题,请使用您的主机文件将地址添加到您的机器,而不是使用主机文件中给出的名称而不是 IP。

If you do not want to temper with the host file try to look at the alternate solution to enable the TCP/IP which is disabled by default.如果您不想修改主机文件,请尝试查看替代解决方案以启用默认禁用的 TCP/IP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM