Saturday, 4 May 2013

HResult 0x2, Level 16, State 1 Named Pipes Provider: Could not open a connection to SQL Server [2]. ...Microsoft SQL Server Native Client 10.0 : Login timeout expired.

With three SQL Server (Express) instances running, typing SQLCMD at a command line caused error:

HResult 0x2, Level 16, State 1
Named Pipes Provider: Could not open a connection to SQL Server [2].
Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : A network-related or in
stance-specific error has occurred while establishing a connection to SQL Server.
Server is not found or not accessible. Check if instance name is correct and if
SQL Server is configured to allow remote connections. For more information see
 SQL Server Books Online..
Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : Login timeout expired.


Some online sources I checked for a solution suggested making sure that in addition to the 'Shared Memory' protocol, that 'Named Pipes' and 'TCP/IP' protocols were also enabled (via SQL Server Configuration Manager).

However none of those steps resolved the issue. It seems the error can also be the result (if you have multiple Sql Server instances running) of not specifying a particular Sql Server instance-name in the SQLCMD command line, eg:

C:\>SQLCMD

instead, this should be:

C:\>SQLCMD -S ServerName\InstanceName

Where ServerName and InstanceName are strings pointing to a) name of the server - aka 'Computer Name' - hosting your database and
b) the service name of a running instance of Sql Server, respectively.

For example the default instance-name for a free SQL Server Express installation is SQLEXPRESS, whereas for a licensed copy this is usually MSSQLSERVER.

No comments:

Post a Comment