RayofCommand
RayofCommand

Reputation: 4244

Stopping Powershell script to continue after an SQL error inside of the script fails?

I have a PS script which connects to MS SQL and makes changes in the DB and if the SQL script fails, my ps script still continues with the next steps. So I wonder what is a good way to stop the script after it failed on SQL side? My Powershell didn't recognize the normal abortion from SQL, so is the another way?

Upvotes: 0

Views: 260

Answers (3)

mjolinor
mjolinor

Reputation: 68263

This is basic error handling. See if this help:

http://www.microsoftvirtualacademy.com/Content/ViewContent.aspx?et=3447&m=3443&ct=18350#?fbid=8N34OvP1Y5K

Upvotes: 1

Chad Miller
Chad Miller

Reputation: 41777

Take a look at $ErrorActionPreference. You can set this at a script level to Stop.

Upvotes: 1

Paul
Paul

Reputation: 5861

If you find a way to check if your SQL script worked or not (if you don´t know how you should provide a little more info on what you are doing), you can use Break to stop your powershell script.

Upvotes: 1

Related Questions