Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Sql Job error Handling

Author  Topic 

snarayan
Starting Member

10 Posts

Posted - 2004-06-17 : 18:37:11
Hi

Running a SQL job that imports records from another SQL server and processes the records. The Job runs every 2 minutes.

Once a while the processing part fails, error message is 2627 - Primary Key constraint. This is not a problem as I can handle this error ie

Insert into mytable Select * from source
Select @ret = @@Error

If @ret = 2627 Begin
-- do error handling

End

When I execute the Stored Procedure from SQL Query Analyser, the error is reported but the stored Procedure is not terminated and error handling code is executed.

But when the stored procedure is executed as part of a SQL job, the job terminates and error handling code is not executed.

How can I catch the SQL error within the job ie stop the job from terminating?

Thanks
Sanjay



derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-06-17 : 23:49:14
You could move this into a DTS package. On failure go one direction. On success go another. That would be the easiest solution. You could then just schedule the package.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -