8

When I try to run sqlcmd (from the cmd prompt) I get the following 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 i f 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.

Not sure why this happens? I can connect to the sql server from within my asp.net website (which runs locally, like the database) but sqlcmd can't connect.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
meds
  • 21,699
  • 37
  • 163
  • 314

2 Answers2

14

If you are not using the default instance, the try then following command:

sqlcmd -S MACHINENAME\INSTANCE_NAME

Notice the capital S. Also notice that I did not give it a user of password, given that default sqlcmd authentication is the windows auth, so I can log in as the current user.
For more information from Microsoft check this out > http://msdn.microsoft.com/en-us/library/ms165702.aspx

Community
  • 1
  • 1
dev4life
  • 10,785
  • 6
  • 60
  • 73
  • 4
    thank you for pointing out the case-sensitivity of the argument flag – Dave Cousineau Sep 04 '15 at 21:10
  • 2
    Not sure if this will help anyone, but I tried the machine name and it did not work for me - I had to use "localhost". I have TCP/IP enabled (for local development), and had to use "localhost" instead of the actual name (seems that the TCP/IP listener was listening only on some IPv6 addresses [which my machine name resolves to], and the loopback address [127.0.0.1] as well, which was the only thing that worked [IPv6 bug?]). – James Wilkins Mar 09 '17 at 01:45
11

Try sqlcmd -S <InstanceName>

  • Your command will work only if you have installed the server as default instance.
  • Run sp_helpserver to know the instance name.
anivas
  • 6,437
  • 6
  • 37
  • 45