- Marco Meoni
- SnapDevelop
- Thursday, 26 October 2023 08:46 PM UTC
Hello,
would anyone advise on how to efficiently setup user impersonation in a datacontext?
In PB I can connect a DB as dba and then issue the statement EXECUTE AS mmeoni, so that all subsequent SQL statements will execute as user mmeoni, but still use the connection established with the dba user.
How the API would handle this with the connection pool?
I'd rather avoid wrapping each request into an explicit transaction with upfront EXECUTE AS:
_context.BeginTransaction();
ls_sql = "EXECUTE AS " + username;
_context.SqlExecutor.ExecuteNonQuery(ls_sql, out SqlResult sqlResult);
// any transaction here will impersonate user mmeoni
_context.Commit();
Ideally, impersonation should happen when an instance of datacontext is injected into the service class.
Any suggestion will be welcome.
Cheers,
.m
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.