trying to run sqlcmd fails, unable to establish connection?

折月煮酒 提交于 2019-12-08 17:19:16

问题


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.


回答1:


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.



回答2:


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



来源:https://stackoverflow.com/questions/4012526/trying-to-run-sqlcmd-fails-unable-to-establish-connection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!