?
Solved

Stored Procedure check Permissions SQL Server 2000

Posted on 2004-03-31
6
Medium Priority
?
1,600 Views
Last Modified: 2012-05-04
I have a stored procedure that I pass a table name into as a parameter from vb.net.  I could also pass in user name if I cannot get it from sql server.

Is it possible for me to see if a user executing the stored procedure has select rights on the table and exit if not?

My table permissions are set by roles (ie. I have three users in a role)  I have granted permissions to the role and not each of the three users.

Thanks
0
Comment
Question by:barnetjeb
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:kiprimshot
ID: 10725925
sp_helprotect 'table_name' will tell you the permissions for a table...by permission group
0
 
LVL 2

Assisted Solution

by:kiprimshot
kiprimshot earned 400 total points
ID: 10726131
sp_helprolemember 'RoleName' will tell you all the members of a role

both together could get you what you want... but there may be a better way
0
 
LVL 7

Expert Comment

by:Lori99
ID: 10726582
How about this.  Execute a simple SELECT against the table requested and check for a 'permission denied' error message.  I think the message number you want would be 229.  It would probably be more efficient and easier than executing multiple stored procedures to determine the user's permissions.
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

Author Comment

by:barnetjeb
ID: 10727027
I have a stored proc like this

Set @strsql = 'delete from ' + @table_name + ' where ' + @id_field + ' = ' +  @id_value
exec @strsql

I think I ran into it before that it would just go ahead and execute this if the user had execute permissions on the stored procedure even though he did not have delete permissions on the table.

I was thinking I could do some sort of check first to make sure the user has delete permissions, if not exit my stored proc.



0
 
LVL 7

Expert Comment

by:Lori99
ID: 10727179
Good point.  Even though you mentioned this was a stored procedure, I didn't take that into account.  You could use SYSTEM_USER to determine who is executing the procedure.  Then do as kiprimshot mentions above and use sp_helprotect and sp_helprolemember to figure out if they are allowed to delete from the table.  It seems like there should be a better way.  I'll keep thinking about it.
0
 
LVL 7

Accepted Solution

by:
Lori99 earned 1600 total points
ID: 10727370
I found something you can use.  There is a PERMISSIONS function that will validate a user's object permissions.  The syntax is something like this.

if PERMISSIONS(OBJECT_ID(@table_name)) &0x10 = 0x10
  <user can delete, go ahead and delete>
else
  <user can't delete, kick them out of here>

The bitmap used varies based on what object permissions you want to check.  See this link for more information on syntax and usage.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_pa-pz_6f78.asp
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question