application-role

Detecting unusable pooled SqlConnections

When I attempt to set an application role on a SqlConnection with sp_setapprole I sometimes get the following error in the Windows event log... The connection has been dropped because the principal that opened it subsequently assumed a new security context, and then tried to reset the connection under its impersonated security contex...

How can I detect condition that causes exception before it happens?

I had no luck with this question so I've produced this simple-as-possible-test-case to demonstrate the problem. In the code below, is it possible to detect that the connection is unusable before trying to use it? SqlConnection c = new SqlConnection(myConnString); c.Open(); // creates pool setAppRole(c); // OK c.Clo...