简体   繁体   中英

Very slow SQL query when using IP in connection string

I am having a real big headache with slow SQL query. 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. The first connects using the database instance name, while second connects using IP address (over the internet to the system) and port number.

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.

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.

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 .

Is there a way to route all IP address to 127.0.0.1 on the machine?

I need ConnectString2 to work query will be pushed over the IP address from other systems outside the LAN.

Note: I am using SQL Server 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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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