1

I'm currently researching the ability for a T-SQL trigger to fire off the printing of an SSRS report when records are inserted into a table. The closest thing I've found to accomplish this are in ScottLenart's comments here. I have a few parameters I need to pass to the report and I want to send the print job to a specific network printer. I'm wondering if this is something I could build into a SQL CLR assembly (though I know that seems like the wrong way to use SQL CLR), or if using the xp_cmdshell to kick off some custom c# app that prints it is my best approach.

I figure I may have to look into using some kind of queue to put the print requests into when the trigger fires so that it doesn't block a bunch of other queries while things are printing, or something, but I'm trying to figure out how to get the document printed as close as I can to when the record is created or updated in the database.

I'm looking to deploy this with SQL Server 2012

Community
  • 1
  • 1
mttjohnson
  • 462
  • 3
  • 13

2 Answers2

0

It is probably doable, but this is not something you should do. Imagine you're in the middle of transaction, holding locks and blocking access to resources, and someone has to feed paper to the printer?

If you really have a strong business case on doing it this way, use service broker to make the call async (so the transaction may commit and release the resources).

dean
  • 9,960
  • 2
  • 25
  • 26
0

Use a trigger to insert records into a "print queue" table of some sort. Have a scheduled SQL Server job that emulates ScottLenart's process from there onward. dean is right - don't have the trigger doing the actual execution of the report/print operation; merely use the trigger to pass/prep that workload to another process.

kyzen
  • 1,579
  • 1
  • 9
  • 13