如何使用 Windows 身份验证从命令提示符连接到 SQL Server
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22552102/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to connect to SQL Server from command prompt with Windows authentication
提问by Abdullah Leghari
How can I connect to SQL Server from command prompt using Windows authentication?
如何使用 Windows 身份验证从命令提示符连接到 SQL Server?
This command
这个命令
Sqlcmd -u username -p password
assumes a username & password for the SQL Server already setup
假定已设置的 SQL Server 的用户名和密码
Alternatively how can I setup a user account from command prompt?
或者,如何从命令提示符设置用户帐户?
I've SQL Server 2008 Express on a Windows Server 2008 machine, if that relates.
如果相关,我在 Windows Server 2008 机器上安装了 SQL Server 2008 Express。
回答by Pjarenee
You can use different syntax to achieve different things. If it is windows authentication you want, you could try this:
您可以使用不同的语法来实现不同的目的。如果它是你想要的 Windows 身份验证,你可以试试这个:
sqlcmd /S /d -E
If you want to use SQL Server authentication you could try this:
如果你想使用 SQL Server 身份验证,你可以试试这个:
sqlcmd /S /d -U -P
Definitions:
定义:
/S = the servername/instance name. Example: Pete's Laptop/SQLSERV
/d = the database name. Example: Botlek1
-E = Windows authentication.
-U = SQL Server authentication/user. Example: Pete
-P = password that belongs to the user. Example: 1234
Hope this helps!
希望这可以帮助!
回答by Vipin Mittal
回答by Madara Uchiha
This might help..!!!
这可能会有所帮助..!!!
SQLCMD -S SERVERNAME -E
回答by Vityata
After some tries, these are the samples I am using in order to connect:
经过一些尝试,这些是我用于连接的示例:
Specifying the username and the password:
指定用户名和密码:
sqlcmd -S 211.11.111.111 -U NotSA -P NotTheSaPassword
Specifying the DB as well:
还指定数据库:
sqlcmd -S 211.11.111.111 -d SomeSpecificDatabase -U NotSA -P NotTheSaPassword
回答by jaswanth
type sqlplus/"as sysdba" in cmd for connection in cmd prompt
在 cmd 中键入 sqlplus/"as sysdba" 以在 cmd 提示符下进行连接
回答by Afazal
here is the commend which is tested Sqlcmd -E -S "server name" -d "DB name" -i "SQL file path"
这是测试的命令 Sqlcmd -E -S "server name" -d "DB name" -i "SQL file path"
-E stand for windows trusted
-E 代表受信任的 Windows