开发者

Console app doesn't print when executing with xp_cmdshell under sql server agent proxy

开发者 https://www.devze.com 2023-03-24 09:45 出处:网络
I have a requirement to automatically print an ssrs report to a specific printer on the network whenever a n开发者_运维百科ew row is inserted into a database table.There is a trigger on the database t

I have a requirement to automatically print an ssrs report to a specific printer on the network whenever a n开发者_运维百科ew 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.)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消