在 sql server 代理代理下使用 xp_cmdshell 执行时控制台应用程序不打印

发布于 2024-11-27 07:07:02 字数 953 浏览 2 评论 0原文

我需要在将新行插入数据库表时自动将 ssrs 报告打印到网络上的特定打印机。数据库表上有一个触发器,它使用 xp_cmdshell 调用呈现和打印报告的控制台应用程序。当我从命令提示符执行控制台应用程序时,它可以工作。另外,当我将 sql server 运行的帐户更改为管理员时,xp_cmdshell 按预期工作并打印报告。但是,我不希望 sql server 以管理员身份运行,因此我使用 sp_xp_cmdshell_proxy_account 设置了一个代理帐户。我使用管理员作为 SQL Server 执行 xp_cmdshell 的帐户,并将 SQL Server 设置为作为本地系统运行。但是,当我使用非 sysadmin 帐户登录 SQL Server 并使用 xp_cmdshell 执行控制台应用程序时,控制台应用程序会生成以下异常:

RPC 服务器不可用 - Source:System.Drawing - Stack Trace: at System.Drawing。 Printing.StandardPrintController.OnStartPrint(PrintDocument 文档,PrintEventArgs e) 在 System.Windows.Forms.PrintControllerWithStatusDialog.OnStartPrint(PrintDocument 文档,PrintEventArgs e)在 System.Drawing.Printing.PrintController.Print(PrintDocument document) 在 System.Drawing.Printing.PrintDocument.Print() 在 PrintQCChecklist.Program.Main(String[] args)

然后我用 xp_cmdshell 调用 whoami.exe 并返回 '行政人员'。为什么当 sql server 以管理员身份运行时会打印文档,但在以管理员身份在代理下运行时会崩溃??? (请不要因为使用xp_cmdshell而咬我的头。我知道安全风险。谢谢。)

I have a requirement to automatically print an ssrs report to a specific printer on the network whenever a new row is inserted into a database table. There is a trigger on the database table which uses xp_cmdshell to call a console application which renders and prints the report. When I execute the console application from the command prompt it works. Also, when I change the account that sql server runs as to administrator, xp_cmdshell works as expected and the report is printed. But, I do not want sql server to run as administrator so I set up a proxy account, using sp_xp_cmdshell_proxy_account. I used administrator as the account that SQL Server executes xp_cmdshell as and set SQL Server to run as Local System. However, when I log into SQL Server with an account that is not sysadmin and execute the console app with xp_cmdshell the console app generates the following exception:

The RPC server is unavailable - Source:System.Drawing - Stack Trace: at System.Drawing.Printing.StandardPrintController.OnStartPrint(PrintDocument document, PrintEventArgs e) at System.Windows.Forms.PrintControllerWithStatusDialog.OnStartPrint(PrintDocument document, PrintEventArgs e) at System.Drawing.Printing.PrintController.Print(PrintDocument document) at System.Drawing.Printing.PrintDocument.Print() at PrintQCChecklist.Program.Main(String[] args)

I then called whoami.exe with xp_cmdshell and it returns 'administrator'. Why would a document print when sql server is running as admin but crash when running under a proxy as admin??? (Please do not bite my head off for using xp_cmdshell. I am aware of the security risks. Thank you.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一抹苦笑 2024-12-04 07:07:02

您是否考虑过将 SSRS 报告发布到网络共享,并让打印机程序拾取该报告、打印它,然后将其存档?我曾经使用廉价的第三方打印工具做过类似的事情 - 由供应商支持,而且 - 在我看来 - 更干净。

Have you thought about publishing the SSRS reports to a network share, and have a printer program pick up the report, print it, and then archive it? I used to do something similar with a cheap third party printing tool - supported by the vendor, and - in my mind - cleaner.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文