Saturday, July 23, 2011

Check database permission

Check Access to Database

Check if user has access to the specified database

HAS_DBACCESS returns 1 if the user has access to the database, 0 if the user has no access to the database, and NULL if the database name is not valid

Begin
Declare @RetValue Int;
Set @RetValue = HAS_DBACCESS('AdventureWorks') 
IF @RetValue = 1 
Print 'User has Access';
Else
IF @RetValue = 0 
Print 'User Does not have Access';
Else
Print 'Database name is not valid';
End

Check for Valid Database Name, DB Name Error, DB Name Validity, User Permissions for DB, User Access for DB, User Rights for DB, SQL Server Check Access to database

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Deep's | Bloggerized by Deep - Deep's Templates | ElearSQL-Server