Sql-server – SQL Server connection string question

sql server

I'm trying to connect to a named SQL instance on the server.
There is already default instance of SQL Server 2005 and a newly named one – SQL Server 2008. I'm using the "Network library" property to use TCP connection but for some reason, he try's to connect the default instance and omit an error about login error.

If I remove the network library propery the connection established as well without any error.

I'm using windows authntication and have all the permissions needed.

The problematic connection string:

Data Source=ServerName\InstanceName,1433;network library=dbmssocn;Initial Catalog=MyDataBaseName;Integrated security=SSPI

The working connection string:

Data Source=ServerName\InstanceName;Initial Catalog=MyDataBaseName;Integrated security=SSPI

I would like to understand why, please.
Thanks in advance,

Tamir

Best Answer

The connection strings have 2 differences so I'll try to answer for this...

  • Named instances do not listen on port 1433 (only the default instance by, er, default)
  • The instance name is ignored when the port is specified

So:

  • ServerName\InstanceName,1433 means connect to server "ServerName" on port 1433
  • ServerName\InstanceName means connect to server "ServerName" and resolve instance name to correct port (resolve uses port 1434 UDP)

However, network library=dbmssocn means use tcp. It could be the SQL Server instance (see port stuff) does not listen on tcp

Related Topic