当我尝试使用sqlcmd实用程序连接到sql server时,我使用以下语法:
sqlcmd -q "SELECT * FROM AdventureWorks2008R2.Person.Person"
我得到以下错误,任何人都可以请求帮助。
HResult 0x2, Level 16, State 1
Named Pipes Provider: Could not open a connection to SQL Server [2].
Sqlcmd: Error: Microsoft SQL Native Client : An error has occurred while establi
shing a connection to the server. When connecting to SQL Server 2005, this failu
re may be caused by the fact that under the default settings SQL Server does not
allow remote connections..
Sqlcmd: Error: Microsoft SQL Native Client : Login timeout expired.
答案 0 :(得分:3)
提供您想要连接的服务器:
sqlcmd -S <server> -q "SELECT * FROM AdventureWorks2008R2.Person.Person"
例如,如果您使用SQL Server Express <server>
将是.\SQLEXPRESS
有关sqlcmd
使用sqlcmd -?
答案 1 :(得分:0)
sqlcmd -S <server> -d <database> -q "query"
这种语法对我来说非常有用......
答案 2 :(得分:0)
首先连接到SQL Server,如下:
C:\>sqlcmd -U sa -P your_password
然后输入查询:
SELECT * FROM AdventureWorks2008R2.Person.Person;
如果要退出sqlcmd,只需输入:
quit
然后输入。