lapots
lapots

Reputation: 13415

how to check whether user is admin

I want to block functionality of my client application if user is not admin. But the problem is how to check in program that login and password was admin's?

Upvotes: 0

Views: 607

Answers (3)

NG.
NG.

Reputation: 6073

SELECT IS_SRVROLEMEMBER('sysadmin', 'YourLogin')

or Run the following stored procedure which will give you all the permissions associated with any user.

sp_helprotect @username = 'guest'

Upvotes: 0

user1704366
user1704366

Reputation:

In ASP.Net you will use Page.User.IsInRole("RoleName") or in Windows you can use System.Threading.Thread.CurrentPrincipal.IsInRole("RoleName")

Upvotes: 0

user
user

Reputation: 6947

I'm assuming two things:

  1. You want to know whether the logged-in user is an administrator or not in the SQL Server context.
  2. There is some role which all "administrator" users belong to, such as for example db_owner. (Sorry, I don't have SQL Server in front of me and don't remember all the role names off the top of my head, so I'm pulling one that is close enough out of the MSDN documentation page example.)

If these assumptions hold, then it looks like IS_MEMBER will work.

Upvotes: 1

Related Questions