After installing XP SP2 on the machine that runs my SQL Server, I found I could no longer access my SQL Server database from within the Visual Studio 2005 IDE or from any new applications created with Visual Studio 2005. Prior to installing SP2 the SQL Server was accessible and everything worked fine; now I get timeout errors from the SQL Server and my connection fails. L
What’s going on here!! Why can’t I connect to the SQL Server on my Windows XP SP2 box?
It seems that installing SP2 automatically turns on the Windows Firewall, essentially cutting off communication to the SQL Server. When the Windows Firewall is enabled, it blocks communication to the SQL Server over TCP/IP, which is the primary protocol used by the .NET Framework Data Provider (System.Data.SqlClient.SqlConnection). When the SqlConnection tries to connect to the SQL Server over TCP/IP, the firewall blocks the connection, and the timeout error occurs.
Well almost….
Strange thing is, I could still access the SQL Server from older versions of Visual Studio (2002 and 2003), as well as applications written with these versions?
So, why can I connect using Visual Studio 2003?
Basically, applications written against ‘Version 1’ of the .Net Framework use named pipes as the primary protocol when connecting to SQL Server. The firewall does not block communication using named pipes, and therefore allows the connection! Version 2 of the .NET Framework attempts to connect to the SQL Server using TCP/IP. Because the firewall is preventing communication over TCP/IP the connection fails, and the timeout error is raised.
That’s all nice to know – BUT HOW DO I FIX THE PROBLEM AND CONNECT TO MY SQL SERVER!!
You can do one of the following:
1) Modify settings on the client – You can adjust the connection string to use Named Pipes as the primary protocol. Do this by adding ‘np:’ (named pipes) in front of the SQL Server instance name. For example, if your SQL Server instance is named ‘SalesDatabase’ the connection string argument should be: ‘Data Source=np:SalesDatabase’. This will force the connection into using named pipes as the primary protocol.
You can add the np: to the server name directly in the Server name box on the Add Connection dialog box. Change connections already saved in application settings by opening the Project Designer and editing the desired connection string setting. For detailed instructions on editing connection strings in your application, see the How to: Edit a Connection String topic in the Visual Studio help.
-or-
2) Modify settings on the SQL Server – If you can make changes on the machine that hosts the SQL Server you can adjust the settings of the firewall to allow communication with the SQL Server. Add the SQL Server (sqlserver.exe) as an exception to the firewall. This allows TCP/IP communication between clients and the SQL Server to bypass the Windows firewall. For detailed instructions on adding SQL Server as an exception to the firewall, see http://support.microsoft.com/?kbid=841249.
After performing one of the above steps you should be able to access your SQL Server as expected!
-Steve
0 comments
Be the first to start the discussion.