Sql-server – SQL Server: Should we use TCP or Named Pipes or use the default

Networksql serversql-server-2008-r2

When connecting to a SQL Server 2008 R2 from a .NET 4 client application on a different server in the same LAN, one can set three different network protocols:

  1. TCP
  2. Named Pipes
  3. Don't set anything in the connection string and use the default

What is best practice? What to choose?

Additional information: Both TCP and Named Pipes are enabled both on the server and on the client. The application is using database mirroring. Client and server communicate over a fast LAN.

We are investigating this because we have rare and spurious connectivity and timeout problems. (But regardless of that I'd like to know the best practice).

There is an article on this subject on MSDN but it is very generic and vague. It does not advise or recommend anything useful.

Best Answer

I prefer TCP/IP over Named Pipes, even though in most situations there will be no noticeable difference. You can do this by adjusting the protocols supported by the instance in SQL Server Configuration Manager rather than hard-coding things in your connection string (this makes it easier to make changes or to troubleshoot).

Essentially the routing and other overhead involved with named pipes (unless your apps are on the same machine as SQL Server, in which case there is only a little extra overhead) make it the less efficient option, especially at scale, in a slower network environment (100MB or less), or if your workloads come in bursts.

If your apps are on the same box as SQL Server, you should also keep shared memory in mind - if you have applications on the SQL Server box directly communicating with SQL Server, this is going to be the most efficient option.

You can read about the performance advantages of TCP/IP in more detail.