1

I have a SQL CLR Trigger that has a number of SqlDataReader calls in it (among other things), where in the production system users are getting errors like

A .NET Framework error occurred during execution of user-defined routine or aggregate "MyTrigger":
System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.
System.InvalidOperationException:
at
System.Data.SqlClient.SqlInternalConnectionSmi.ValidateConnectionForExecute(SqlCommand command)
...

however I am unable to reproduce this in my test env. I am considering setting MutltipleActiveResultSets=true, but of course there is no connection string to define in the CLR Trigger (or is there...) - so is it possible to set MARS to true somewhere here, or do I need to keep looking for an alternate solution?

Conrad
  • 2,197
  • 28
  • 53

1 Answers1

2

If you specify the in-process Context Connection, then no, you cannot enable MARS. This restriction is documented.

If you want / need a MARS connection, then you need to use a regular / external connection. That will require setting the Assembly to EXTERNAL_ACCESS. It also means that you are not working "in process" and so won't have access to the the session that is executing the Trigger.

Solomon Rutzky
  • 46,688
  • 9
  • 128
  • 171