Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've setup the instance SQLEXPRESS via SQL Server 2008 R2 installation, added a security login with all server roles, one called 'sqluser'.

The server authentication is SQL Server and Windows Authentication mode. However, when i specify the -S property, login fails.

There is no firewall enabled and SQL server even accepts connections from remote hosts.

C:\Users\user>sqlcmd -U sqluser -P qwerty -Q "Select * FROM testdb.dbo.testtable"



(4 rows affected)

However when specifying 'localhost' the query fails... Question is Why?

C:\Users\user>sqlcmd -S localhost/sqlexpress -U cpt -P 1234 -Q "Select * FROM cpt.dbo.testme"


HResult 0x43, Level 16, State 1
Named Pipes Provider: Could not open a connection to SQL Server [67].
Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : A network-related or in    stance-specific error .....
Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : Login timeout expired.

Changing 'localhost' with '%COMPUTERNAME' is same result if someone would be wondering. The server is running as a LocalSystem instance.

share|improve this question
up vote 1 down vote accepted

You need to specify the -S switch to provide the instance name for sqlcmd to connect to, and it should be in the format "localhost\sqlexpress" instead of "localhost/sqlexpress".

share|improve this answer
got it, thx - actually finally found out last night :) – mschr Nov 12 '12 at 15:41
glad you got it working, thanks for the answer. – Jason Cumberland Nov 12 '12 at 16:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.