Cannot connect to [database name]. A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 53)

Server Name: Make sure you are typing server name (i.e. host name or computer name) correctly along with the proper instance name of an installed instance of SQL Server.

As, even using ‘(local)’ or ‘(localhost)’ can also cause this error:

Correct format is: Server-name\db-instance-name. e.g. Server01\SQLExpress2008

Also (if using Windows Authentication mode) make sure the format of the username is as follows: Server-name\User-name. e.g. Server01\Administrator

Advertisements

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.