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?
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 theInnerExceptionvalue.