How to connect Sqlcmd to the server?

跟風遠走 提交于 2019-11-29 00:30:38

问题


I just installed SQL Server 2008, and I wanted to use the command editor to execute queries.

To do that I opened the command prompt, and I typed

Sqlcmd -S Serverinstance

but I got an error saying :

Named Pipes Provider: Could not open a connection to SQL Server [53].
Sqlcmd : erreur : Microsoft SQL Server Native Client 10.0 : A network-related or instance-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 if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
Sqlcmd : erreur : Microsoft SQL Server Native Client 10.0 : Login timeout expired

What should I do to get it connected to the server so I can proceed?

Thank you :D.


回答1:


(This one is going to sounds silly) my problem was that I wasn't using capital 'S'

Eg:

C:\> SQLCMD -S localhost\sqlexpress



回答2:


You need to either use the integrated-security approach of using your Windows credentials to connect to SQL Server by specifying -E as an option:

C:\> SQLCMD -S Serverinstance -E

or then you need to define a user/password set to achieve a SQL Server login:

C:\> SQLCMD -S Serverinstance -U (login in) -P (password)

All the many SQLCMD parameters are well-documented on MSDN SQL Server Books Online!




回答3:


The server you are specifying cannot be found or is not accessible. so either the server is wrong (have you spelt it correctly) or you are not specifying it correctly or it is not accessible from your machine.

After you've got that right, you will need to specify a username/password or a -E command qualifier for a Trusted Connection. You may also need to specify the database with a -d qualifier.

You can get help by typing

Sqlcmd -?


来源:https://stackoverflow.com/questions/14197802/how-to-connect-sqlcmd-to-the-server

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