通过命令行和Windows身份验证连接到网络中的SQL Server

时间:2022-01-03 02:11:26

From the system where the server is running, I can login using the following command:

从运行服务器的系统,我可以使用以下命令登录:

sqlcmd -S "ComputerName\InstanceName" -d "DatabaseName" -i "sql.txt" -s"," -o "result.csv"

I want to connect to this server from another machine, So I tried this

我想从另一台机器连接到这台服务器,所以我尝试了这个

sqlcmd -U "UserName" -S "ComputerName\InstanceName" -d "DatabaseName" -i "sql.txt" -s"," -o "result.csv"

"UserName" above is the default user name of the server machine that has administrative privileges. This user account does not have any password.

上面的“UserName”是具有管理权限的服务器计算机的默认用户名。此用户帐户没有任何密码。

After issuing that command, it asks for password. Since there is no password, I hit enter. But I get the following error:

发出该命令后,它会要求输入密码。由于没有密码,我点击输入。但是我收到以下错误:

Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : Login failed for user 'UserName'..

SQLCMD Reference

2 个解决方案

#1


2  

i met this situation:

我遇到了这种情况:

sqlcmd -S "server" -d "db" -E   -i test.sql 

which gives "Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : Login failed for user 'DOMAIN\administrator'.."

这给出了“Sqlcmd:错误:Microsoft SQL Server Native Client 11.0:用户'DOMAIN \ administrator'登录失败'..”

but when i switched to:

但当我切换到:

sqlcmd -S server -d db -E   -i test.sql 

it works fine. so look out for your double quotes. hope this maybe of help.

它工作正常。所以请注意你的双引号。希望这可能有所帮助。

#2


1  

-U UserName specifies the name of a SQL Server login, not a Windows user. It seems to me you want to use a Windows user. The proper way to do it is to have a domain, run as a domain user and grant appropriate permissions in SQL to domain group of which you are member. Bare that, you can use runas /netonly /user:ComputerName\UserName sqlcmd -E.

-U UserName指定SQL Server登录名,而不是Windows用户。在我看来,你想要使用Windows用户。正确的方法是拥有一个域,以域用户身份运行,并将SQL中的适当权限授予您所属的域组。不敢这样,你可以使用runas / netonly / user:ComputerName \ UserName sqlcmd -E。

#1


2  

i met this situation:

我遇到了这种情况:

sqlcmd -S "server" -d "db" -E   -i test.sql 

which gives "Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : Login failed for user 'DOMAIN\administrator'.."

这给出了“Sqlcmd:错误:Microsoft SQL Server Native Client 11.0:用户'DOMAIN \ administrator'登录失败'..”

but when i switched to:

但当我切换到:

sqlcmd -S server -d db -E   -i test.sql 

it works fine. so look out for your double quotes. hope this maybe of help.

它工作正常。所以请注意你的双引号。希望这可能有所帮助。

#2


1  

-U UserName specifies the name of a SQL Server login, not a Windows user. It seems to me you want to use a Windows user. The proper way to do it is to have a domain, run as a domain user and grant appropriate permissions in SQL to domain group of which you are member. Bare that, you can use runas /netonly /user:ComputerName\UserName sqlcmd -E.

-U UserName指定SQL Server登录名,而不是Windows用户。在我看来,你想要使用Windows用户。正确的方法是拥有一个域,以域用户身份运行,并将SQL中的适当权限授予您所属的域组。不敢这样,你可以使用runas / netonly / user:ComputerName \ UserName sqlcmd -E。