5

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

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
swilliams
  • 532
  • 3
  • 11

2 Answers2

2

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.

Eugene Niemand
  • 721
  • 6
  • 28
0

it sounds like you're doing the right thing, and it should work.

if i had to guess, i'd say:

  • you may be ignoring errors (:on error ignore somewhere in your project? sqlserver or your environment are configured to treat errors as warnings and ignore them?)
  • you may not actually be throwing the errors - can you post a sample script somewhere for us to see?
blueberryfields
  • 45,910
  • 28
  • 89
  • 168