SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Setting return status from CLR procedure


Setting return status from CLR procedure

Author
Message
mcginn
mcginn
SSC-Addicted
SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)

Group: General Forum Members
Points: 486 Visits: 316
I have a CLR C# DLL. It contains a try/catch loop. I am using the SqlContext.Pipe method to pipe the error messages back to the client. The messages are trapped and returned, but the status of the procedure always returns a 0. What can be done such that the CLR procedure will return a status of 1 or non-zero in case of error?

Kevin McGinn
Elliott Whitlow
Elliott Whitlow
SSC-Insane
SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)

Group: General Forum Members
Points: 23556 Visits: 5314
Instead of defining it as a sub define it as a function with a return value of sqlint (I think thats how I did it)..

I did it in VB though..

CEWII
mcginn
mcginn
SSC-Addicted
SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)

Group: General Forum Members
Points: 486 Visits: 316
Thankyou for the suggestion. I have only written CLR procedures in the past. I was of the impression that a CLR function would not allow file system I/O which is the fundamental purpose of the CLR. If I am incorrect and a Function CLR does in fact allow file system I/O then I will convert over to a Function type.
Elliott Whitlow
Elliott Whitlow
SSC-Insane
SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)

Group: General Forum Members
Points: 23556 Visits: 5314
If it is added to SQL as a SAFE SQLCLR then it won't be able to, but if it is EXTERNAL_ACCESS or UNSAFE then it can.

CEWII
mcginn
mcginn
SSC-Addicted
SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)SSC-Addicted (486 reputation)

Group: General Forum Members
Points: 486 Visits: 316
The Function solution does work; thank you. However, the stored procedure approach, when implemented correctly, also will return the correct status. I realized that I had the CLR procedure defined as a 'public static void'. I changed that to 'public static int' and returned 1 or 0 depending upon whether errors were encountered and the status is properly returned.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search