We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

skills0
Posts: 1
Joined: Thu Nov 03, 2016 3:46 pm

Significant issues with SQL Server script error handling

Seeing some rather major deficiencies in how Advanced Installer surfaces errors from a sql script. Hopefully I'm missing something, but I've tried a lot of different options to get this to work.

Basically, if your script throws a run-time error, there is no real way to handle this in a way that a) provides fail-safe rollback and b) informs the user appropriately. Here is what I'm seeing:

Consider a basic sql server upgrade script that inserts a row into a table that has a primary key. If you turn on IDENTITY INSERT (common practice in some cases) and attempt to insert a row that already exists, you'll receive a primary key constraint error and your script will stop running. I understand you can check for existence, but that's a whole other topic.

This error IS NOT raised to the installer UI and the installer reports success.

Let's say the line before this did something else like add or drop a column in a table.

Advanced Installer options in this case are abort, run the next line or run the next script in the sequence.

if you abort, your database is left in an interim state where your column add/drop succeeded, but the rest of the script did not.
if you run the next line, you basically end in a different interim state where certain parts of the upgrade succeed or fail based on previous errors.

Neither state is acceptable.

Given that, I wrapped the entire thing in a try-catch, plus a transaction so I can roll it back myself and raise an error

This doesn't work either as far as I can tell from my testing.

if you abort, you are left in the same state as in the first case. Your try-catch never catches the exception and the transaction is not rolled back.

So i tried running the next line in hopes that I would fall into my catch block, rollback my transaction and raise an error that the user can see. No luck.
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Significant issues with SQL Server script error handling

Hello and welcome to our forums,

A correct approach for your scenario is to use the "Abort installation" option for the "On error" flag of your script. In this case an error will be thrown and the installation will be aborted and rolled back. We have support to run an SQL Script on installation rollback too, therefore for each one of your SQL Scripts you execute at install time and whose actions you want to undo on installation rollback, you should create and use an SQL Script configured to run "during rollback".

If you have any questions just let us know.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”