SQL Server – Protocol Used for ODBC and ADO Connection

sql server

We understand when connecting to SQL server that specifying:

  • < ip address>
  • < host or ip>,< port number>

That the ADO or ODBC client will typically use tcpip to connect.

However, we observe that when a client asks to connect to:

< server>\< instance name> that it seems the client (ODBC in this case) does NOT use tcpip.

We believe in some cases, connecting to:

  • < host name>

May also result in a named pipes connection.

Questions:

  • Since < server>\< instance name> is not connecting over tcpip, that means it is using named pipes, right?
  • How do I force the connection to use tcpip?

And is the behavior (of the 32 bit Windows ODBC driver for SQL Server) in this regard the same as the behavior of the old dblib client?

Best Answer

If you don't specify the protocol in the connection string, then it will use the protocol specified for the database driver. The protocol order, by default, is Shared Memory, TCP/IP and then Named Pipes. You could also set a default protocol.

To specify which protocol to use in a connection string, add tcp: before the server name. Examples: tcp:server1\instance1, tcp:server2, tcp:server3,1433

You can use SQL Server Configuration Manager to see the protocol order or regedit to see the default and protocol order.

enter image description here

The regkey is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Client\SNI11.0 for 64-bit applications and HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\MSSQLServer\Client\SNI11.0 for 32-bit applications.

enter image description here