[英]Sql Bat File - authenticate using Windows
I have this bat script for executing some sql files from a folder. 我有这个bat脚本,用于执行文件夹中的一些sql文件。
@ECHO OFF
SET SQLCMD="C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE"
SET PATH="C:\Users\user.name\Desktop\sqls"
SET SERVER="DB1"
SET DB="database_name"
SET LOGIN="DOMAIN\user.name"
SET PASSWORD="password"
SET OUTPUT="C:\Users\user.name\Desktop\OutputLog.csv"
CD %PATH%
ECHO %date% %time% > %OUTPUT%
for %%f in (*.sql) do (
%SQLCMD% -S %SERVER% -d %DB% -U %LOGIN% -P %PASSWORD% -i %%~f >> %OUTPUT% -b -h-1 -s";" -w 700
)
The script doesn't work when I have to use the "Authenticate using Windows" 'though i'm specifying the domain. 尽管我要指定域,但是当我必须使用“使用Windows进行身份验证”时,脚本不起作用。
Is there something wrong with my script? 我的脚本有问题吗?
Thank you. 谢谢。
使用RUNAS
并执行SQLCMD -E
以其他用户身份运行。
You need to run your .bat file as the domain user that will be connecting to the database... and use the -E (case sensitive) switch on the SQLCMD executable. 您需要以将要连接到数据库的域用户身份运行.bat文件...,并使用SQLCMD可执行文件上的-E(区分大小写)开关。
You can shift-right-click and Run as a Different User or your can script it... runas.exe /user:domain\\username somefile.cmd.
您可以右键单击并以其他用户身份运行,也可以编写脚本... runas.exe /user:domain\\username somefile.cmd.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.