Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
479 views
in Technique[技术] by (71.8m points)

sql - How can I use SQLCMD with Windows Authentication (-E,) but without elevated permissions

I'm going to create a script to execute numerous SQL files. I've chose to use SQLCMD instead of ADODB because it provides logging information quickly, and we're executing T-SQL. I'm testing out SQLCMD.exe before putting it into the script.

Connecting to the database using SQLCMD.exe, I utilize -E for Windows Authentication. This means that I need to use my network account, which does not have elevated access on any given machine. However, SQLCMD.exe requires elevated access in order to execute a query, otherwise I receive the following error:

Sqlcmd: Error: Error occurred while opening or operating on file (Reason: Access is denied).

After running the following command:

sqlcmd.exe -S <SQLSERVER,PORT> -d <DATABASE> -i scriptfile.sql -o scriptfile.log -E

How can I utilize SQLCMD.exe with elevated local permissions (Administrator) but use Windows Authentication to connect to the server (using a non-Administrator account)? I'd prefer not to change any permissions of SQLCMD.exe, as there may be multiple people that use this script that I'm not keen on informing them of this prior instruction.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

What path are you running the command from when you test it? Does the non-administrator running the command have access to read from scriptfile.sql and access to write to scriptfile.log? Most commands generally default to the current working directory.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...