inutan
inutan

Reputation: 10888

sqlcmd - connect to local instance of SQLEXPRESS

I want to run a .sql batch script to delete records from a number of tables from cmd window. So, for that I am trying to connect to my local instance of SQLEXPRESS using following command-

sqlcmd -e -s \SQLEXPRESS

However, I am not able to connect and getting following error:

'Named Pipes Provider: Could not open a connection to SQL Server [2]'.

One more weird thing that I notice from the error message is that above command is trying to connect to SQL Server 2005 whereas the instance running on my machine is SQLEXPRESS 2008.

Can anyone please guide.

P.S. I am using Windows Authentication to connect to SQLEXPRESS which is when I go to connect using Mgmt Studio.

Upvotes: 16

Views: 38797

Answers (3)

MarJer
MarJer

Reputation: 107

Just sqlcmd -S .\sqlexpress will also work. But make sure you have capital "S", just as Tao mention above.

Upvotes: 0

luviktor
luviktor

Reputation: 2270

Isn't it possible that the '.' is missing from your command?

sqlcmd -e -S .\SQLEXPRESS

EDIT:

Visit this page. There you fill find some instructions to get connected to your server. First check the Hresult error code in your error message.

I also tried it myself, because I could emulate your problem. I had to do the steps below in order to connect with sqlcmld

  1. Go to All programs\Microsoft SQL Server\Configuration Tools\SQL Server Surface Area Configuration
  2. In Services and connections select SQLEXPRESS\Database Engine\Remote connections
  3. Check Local and remote connections and Using both TCP/IP and named pipes. Click OK.
  4. Restart your database service.
  5. Try to connect to the server:

    sqlcmd -Snp:\\.\pipe\MSSQL$SQLEXPRESS\sql\query
    

Upvotes: 11

Tao
Tao

Reputation: 13986

Sorry about the late response (just came across your question when searching for something unrelated), but it looks to me like you're just using the wrong case on your arguments:

sqlcmd -E -S .\SQLEXPRESS

-S means "server", whereas -s means "colseparator" (and similarly, lowercase e means echo rather than integrated auth)

Upvotes: 40

Related Questions