Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting SQLProj Pre/PostDeploy scripts to fail build

I'm working to deploy SQLProj (Database Project) via VS2013 and I'm encountering an issue that I could use some feedback on.

When I publish changes it executes a CCRD (Create, Copy, Rename, Delete) operation for a table. Create and Copy in the PreDeploy script and the Rename, Delete in the PostDeploy Scripts. I have these statements encapsulated in a Try...Catch block and have it printing out error messages. When the Pre and Post deploy scripts encounter issues the publish completes showing the publish as successful. I'm needing the behavior to be different when these scripts encounter errors. I would like for any errors encountered within these scripts cause the publish to fail. I've tried the THROW command to throw an error and I've tried the RAISERROR command setting severity to 20 when it's executed, which according to BOL should terminate the connection, but still the publish completes with a status of "Successful".

like image 353
swilliams Avatar asked Oct 31 '22 22:10

swilliams


1 Answers

Something we have done is split the process. We use SQLPackage.exe with the script action. Then we use SQLCMD.exe to execute the script. That way you have ONE script that contains your pre/main/post and using SQLCMD will stop execution when errors occur.

like image 116
Eugene Niemand Avatar answered Nov 10 '22 00:11

Eugene Niemand