SQL - Generate a PDF

Nuno Morgado 41 Reputation points
2022-07-19T09:19:59.543+00:00

Hi everybody.
Is it possible to generate a pdf from SQL?

I already have an rpt connected to a SQL database and, if I use Crystal Reports, works fine but I wanted to do it from SQL.

Example, create a trigger that, when an insert occurs in a table, creates a pdf using an rpt.

Thanks in advanced.

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
3,061 questions
SQL Server Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2022-07-19T10:08:10.947+00:00

    It's probably possible by writing a CLR stored procedure for the task, but having this procedure called by a trigger does not sound like the best of ideas. Keep in mind that even if you don't have a user-defined transaction, the trigger will run in a transaction defined by the statement that fired the the trigger. So the INSERT/UPDATE will not commit until that PDF has generated. This could cause some contention issues in a high-transaction environment.

    And what if the PDF generation fails, do you want the INSERT to be rolled back in this case? (Because that is what is going to happen.)

    No, most likely you are better off having some polling mechanism that looks for new rows and generates the PDFs. You could still generate the PDF from a CLR stored procedure, but there is quite a bit of red tape with adding CLR code, and you are probably better off by doing this from an external program. You should probably look into what scheduling opportunities that Crystal may offer


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.