Global exception handler in the CLR stored procedure

I use C # and Sql Server 2008, and I have some try / catch blocks in my CLR stored procedure, and they are caught. They are logged in the file, and they return a code error and message using SqlPipe. These fines work. Now I need to do the same when I have incorrect errors, especially for tracking in the log file!

I tried to use Application.ThreadException, but this class is not available in the CLR (WinForms) stored procedure. Should I use the naughty try / catch block in my input Sql procedure method or is there something better to do?

Thanks.

+8
c # sql sql-server sql-server-2008 clrstoredprocedure
source share
2 answers

As far as I remember, SQL Server will unload unhandled exceptions into its own log file and also return them to the user. You can look at it.

+1
source share

The cleanest approach would be to use the try..catch block in the CLR method called. It would be even better to save the main functions in a separate method, which is called by the CLR write method:

[SqlProcedure] public static void GetSomething(string value) { try { DoGetSomething(value): } catch (Exception ex) { // error handling } } private static void DoGetSomething(string value) { // implementation goes here } 
+1
source share

All Articles