0

I have a SQLCLR scalar function that uses the context connection to read data. Sometimes, the SQL statement being run by the CLR deadlocks.

The scalar function itself is being run in a standard stored procedure, instigated by SqlClient in a .NET Framework application.

I already have code that will catch exceptions and, if they are SqlException instances with a Number deemed transient, will retry the command. However, the SqlException generated when the statement in the SQLCLR throws always has the number 6549, the InnerException property is always null and the Errors collection only ever contains the 6549 error.

I have tried both System.Data.SqlClient and Microsoft.Data.SqlClient and they exhibit the same behaviour.

Other than parsing the string in the Message, which I know I could add to in the SQLCLR by catching and re-throwing, is there any other way of ascertaining the underlying reason for the 6549 error?

4
  • Have you tried placing a try .. catch within your SQLCLR? I remember reading a (very) long time ago, that TSQL places generic exception wrappers around SQLCLR. I have no idea if that is still the case. Commented Jan 24 at 16:21
  • @JonathanWillcock I've tried catching the error and rethrowing it, including the caught exception as the InnerException, which is how I can manipulate the message in the final exception. I think you're right about the wrapper - it's like something is taking the original exception and wrapping it another but just appending the messages together rather than setting the InnerException value. Commented Jan 24 at 16:37
  • If I remember correctly, re-throwing doesn't help you. Instead you need to log the error within the catch. Commented Jan 25 at 10:42
  • if your statement deadlocks your connection is killed, so i'm not sure if you'll be able to recover anything after that anyway. Commented Jan 28 at 16:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.