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.)