Link to home
Start Free TrialLog in
Avatar of RICuser
RICuserFlag for United States of America

asked on

Conditional TRY..CATCH block

Hello Experts,
I am trying to include some logic in a maintenance job step (MS SQL Server 2005-2008)
The job step executes a daily maintenance stored procedure in the database.
The goal is if the stored procedure completes successfully to add logic to reset a maintenance bit (Boolean 0 or 1) in a table in the same database, where 0 means no users are allowed on the database and 1 opens the database to users.
This is important because if there are user connections during the execution of the SP the maintenance will fail, so it is important for the "maintenance bit" as I call it,  to be switched OFF prior , and ON after the successful run of the maintenance SP.
I am trying to incorporate this within the TRY..CATCH block, not sure how.
Please see attached and come up with your suggestions ans examples as to how to accomplish this.

Thank you,
RICUser
Maintenance-Job-Step.txt
Avatar of jogos
jogos
Flag of Belgium image

As your code is now it always be set to 1.

The update to set it on 1 again must be in the try-part (and the catch also can fire on problems with the update) or at least a switch must be set there so  the update can stay where it is (and not possible fire the catch) but then surrounded with a test on that switch
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RICuser

ASKER

Thank you Scott. This is doing what I expected it to do.