Link to home
Start Free TrialLog in
Avatar of plq
plqFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How to tell what application role your connection is currently using

Is there some way to select (e.g. from the sys tables) the current application role ?

I have the classic "General Network Error" caused by calling sp_setapprole when the oledb connection.open method returns a pooled connection. (see http://support.microsoft.com/default.aspx?scid=kb;en-us;Q229564)

If I can detect the application role I can stop this error from happening and still get the performance gains of connection pooling which I think we need.

thanks
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of plq

ASKER

I was just about to delete this. Heres the answer

This will return no rows if you're out of an app role, and a uid if you're in an app role

select a.uid
from master..sysprocesses as a
inner join sysusers as b on a.uid = b.uid
where a.spid = @@spid
and b.isapprole = 1

I think running that select on login before calling sp_setapprole is a better workaround than Microsoft's

Thanks for the answer though - that is a viable alternative.
Avatar of plq

ASKER

Actually my above post didn't work outside of query analyser.