如何在没有提升权限的情况下将 SQLCMD 与 Windows 身份验证(-E,)一起使用 [英] How can I use SQLCMD with Windows Authentication (-E,) but without elevated permissions

查看:30
本文介绍了如何在没有提升权限的情况下将 SQLCMD 与 Windows 身份验证(-E,)一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将创建一个脚本来执行大量 SQL 文件.我选择使用 SQLCMD 而不是 ADODB,因为它可以快速提供日志信息,而且我们正在执行 T-SQL.我正在测试 SQLCMD.exe 然后将其放入脚本.

使用 SQLCMD.exe 连接到数据库,我使用 -E 进行 Windows 身份验证.这意味着我需要使用我的网络帐户,它在任何给定的机器上都没有提升的访问权限.但是,SQLCMD.exe 需要提升访问权限才能执行查询,否则我会收到以下错误:

<块引用>

Sqlcmd:错误:打开或操作文件时出错(原因:拒绝访问).

运行以下命令后:

<前>sqlcmd.exe -S -d <数据库>-i 脚本文件.sql -o 脚本文件.log -E

如何使用具有提升本地权限(管理员)的 SQLCMD.exe 但使用 Windows 身份验证连接到服务器(使用非管理员帐户)?我不想更改 SQLCMD.exe 的任何权限,因为可能有多个人使用此脚本,而我并不热衷于通知他们此先前的说明.

解决方案

您在测试时从哪个路径运行命令?运行该命令的非管理员是否有权读取 scriptfile.sql 和写入 scriptfile.log?大多数命令通常默认为当前工作目录.

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.

解决方案

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.

这篇关于如何在没有提升权限的情况下将 SQLCMD 与 Windows 身份验证(-E,)一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆