Error when trying to call Stored Procedure from batch file

  • Im running the following in a batch file

    sqlcmd -Q "exec dbo.MySproc" -S "MyServer" -d "MyDatabase"

    and Im getting the following error:

    Named Pipes Provider: Could not open a connection to SQL Server [121]

    Any idea what Im doing wrong?

  • dndaughtery (5/22/2013)


    Im running the following in a batch file

    sqlcmd -Q "exec dbo.MySproc" -S "MyServer" -d "MyDatabase"

    and Im getting the following error:

    Named Pipes Provider: Could not open a connection to SQL Server [121]

    Any idea what Im doing wrong?

    You are not specifying to SQLCMD that it should use a trusted connection (-E) or providing a username/password (-U username -P password).

  • Provide User info while connecting using -E or -U switch,

    -E : Is Trusted connection

    -U : UserName to connect and later it will ask for pass to connect

  • Lynn Pettis (5/22/2013)


    dndaughtery (5/22/2013)


    Im running the following in a batch file

    sqlcmd -Q "exec dbo.MySproc" -S "MyServer" -d "MyDatabase"

    and Im getting the following error:

    Named Pipes Provider: Could not open a connection to SQL Server [121]

    Any idea what Im doing wrong?

    You are not specifying to SQLCMD that it should use a trusted connection (-E) or providing a username/password (-U username -P password).

    when I tried his syntax, -E did not need to be included, as its the default according to Microsoft http://msdn.microsoft.com/en-us/library/ms180944.aspx and it worked for me without -E on 2008. I'm suspecting that he might instead not have his server set up for remote connections or has other connectivity issues. By default, SQL server installs with shared memory (local) connectivity only if I'm not mistaken.

  • patrickmcginnis59 10839 (5/22/2013)


    Lynn Pettis (5/22/2013)


    dndaughtery (5/22/2013)


    Im running the following in a batch file

    sqlcmd -Q "exec dbo.MySproc" -S "MyServer" -d "MyDatabase"

    and Im getting the following error:

    Named Pipes Provider: Could not open a connection to SQL Server [121]

    Any idea what Im doing wrong?

    You are not specifying to SQLCMD that it should use a trusted connection (-E) or providing a username/password (-U username -P password).

    when I tried his syntax, -E did not need to be included, as its the default according to Microsoft http://msdn.microsoft.com/en-us/library/ms180944.aspx and it worked for me without -E on 2008. I'm suspecting that he might instead not have his server set up for remote connections or has other connectivity issues. By default, SQL server installs with shared memory (local) connectivity only if I'm not mistaken.

    I'll be honest, I try to never rely on defaults (although I am sure I have on occasions). I have always found it better to explicitly state the connection whether Trusted or using a Username/Password. If someone else needs to work with the code I leave behind they aren't left guessing.

  • LOL editted!

  • dndaughtery (5/22/2013)


    Im running the following in a batch file

    sqlcmd -Q "exec dbo.MySproc" -S "MyServer" -d "MyDatabase"

    and Im getting the following error:

    Named Pipes Provider: Could not open a connection to SQL Server [121]

    Any idea what Im doing wrong?

    Did you try the command on the same computer that the SQL server is running on? If its SQL express, did you supply the instance name also, this typically looks like:

    sqlcmd -Q "exec dbo.MySproc" -S "MyServer\SQLExpress" -d "MyDatabase"

    The reason I mentioned this is that you have to run additional setup to allow remote connections, but this should work right after the install if you run sqlcmd on the same computer the database server is running on.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply