views:

887

answers:

1

We are using SQL 2005 and the try-catch functionality to handle all of our error handling within the DB. We are currently working on deploying a .NET CLR function to make some WCF calls in the DB. This WCF procedure is written in the CLR and then deployed to SQL. If I put a try-catch block in the CLR code, it catches the error fine. However, I can't seem to throw the error up to the try-catch block in SQL. SQL seems to ignore what I throw it and catches the error it finds. Is there no relation between the two (i.e. I can't throw from one to another?)

If I can throw from within the CLR to the calling procedure in SQL, is any special formatting needed? I tried a specific case of catching the error that was thrown, and then throwing a different error, but SQL ignored my thrown error and caught the original error, as if it ignored the thrown error.

+1  A: 

Here is a blog post that covers it at a highish level: Exception handling in SQLCLR

When SQL server execute a user function/procedure/trigger implemented in CLR (i.e., managed code), we will install a managed exception handler around the user code. So if the user code leaked a exception, the server will catch it and throw a TSQL exception wrapping the user exception.

This seems to imply that it will just work.

Larry Smithmier