I've been given the task of writing an web interface for a legacy database we have where all users have database accounts and are assigned roles accordingly (we have triggers all over the place recording when users do certain things, all based on user_name()
).
In order to use anything remotely modern and to avoid storing the user's password in plain text I'm connecting w/ an App-level account that has impersonation privileges for each user, and I'm trying to run Execute As User=@username
and Revert
to set and reset the execution context before and after running any SQL.
Unfortunately, the connection pooling's reset_connection
call is mucking w/ my Connection, and it winds up throwing some nasty errors about Physical connection being invalid...
I can get around this error by not using the connection pool. But then my application user needs an insane amount of privileges to actually perform the impersonation. Furthermore, killing connection pooling is a bummer...
How can I do this without sacrificing security or performance? Keep in mind I can't change the fact that my users have database logins, and I'm really not excited about storing user passwords in a retrievable manner. Is my only option bypassing the connection pool so I can impersonate (and using an sa user so I have sufficient permissions to actually impersonate someone)?
App_Name()
orHost_Name()
functions? Not ideal, but could be an acceptable workaround given the restrictions... – Accommodatinguser_name()
calls withdbo.fn_user_name()
for example? – Maxwellexecute as
– Kenric