question

JosuZatarain-6553 avatar image
0 Votes"
JosuZatarain-6553 asked ErlandSommarskog commented

Impersonate session security context error without applying impersonation

Hi,

So I have an app that creates a SQL connection with MARS enabled and also impersonation, but it doesn't do calls in more than one thread (legacy system), and that app calls a service that also creates a SQL connection with MARS enabled, but without applying impersonation, and that service can run concurrent batches (multiple queries at the same time).

The thing is, that the service is getting the error: "Impersonate Session Security Context" cannot be called in this batch because a simultaneous batch has called it.

Could that be a bug with SQL server trying to join connections or something? The connections in that service are new, so it doesn't make sense to me that an impersonation error appears.

SQL server 2017 - .net framework 4

sql-server-generaldotnet-csharp
· 9
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I think we would need to see a repro of this to understand what is going on. Would it be possible for you to compose one?

0 Votes 0 ·

You're using MARS which stands for Multiple Active Result Sets - so without any further information it's most likely that you have another batch executing on that connection which is issuing another batch, since they are both tied to the same connection it is not letting you impersonate since another batch is already running which is or has called it.

I'd get away from MARS to be quite honest, this doesn't look like a SQL Server issue per se.

0 Votes 0 ·

But shouldn't that batch be processed under the new connection that doesn't apply impersonation?

0 Votes 0 ·

You're assuming that it's on a new connection, which it clearly isn't.

0 Votes 0 ·
Show more comments

0 Answers