Link to home
Start Free TrialLog in
Avatar of VicBel
VicBel

asked on

How to Determine Database Access

I understand that for a SQL Login to have access to a particular database, one of the following things has to occur:

1.Explicit access is granted.
2.The login is a member of the sysadmin fixed server role.
3.The login has CONTROL SERVER permissions (SQL Server 2005/2008 only).
4.The login is the owner of the database.
5.The guest user is enabled on the database.

However, I'd like to know what other conditions have to be true for a user to have access to a database. For example, ownership, etc.

Thanks!

--------------------------------------------------------------------------------
ASKER CERTIFIED SOLUTION
Avatar of lcohan
lcohan
Flag of Canada 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
@Icohan's second link describes what I've done.  I create a login using SQL Server auth and then give that login specific permissions on the database I want them to use making them a 'database user' as described in the article.  No ownership, no roles, nothing more.  You can then use that 'username' and 'password' in a connection string which will give them access to the database and the functions that you have given them permissions to use.
Access could be different: read only, drop table, create procedure, view object definition.

There is a couple USER - LOGIN with the same SID. Very often USER NAME and LOGIN NAME are the same.

LOGIN defines connection to the MS SQL Server Instance.
USER defines - what access to the database LOGIN has.

One LOGIN has a USER for every database where access is needed.
USE database
CREATE user FOR LOGIN login.

What LOGIN can do with a database defined by GRANT  access rights to the USER. It could be different in different databases.

There are predefined roles as you mentioned: db_datareader, db_datawriter, db_owner, db_dlladmin etc.
You can create your own role and GRANT to it something like GRANT EXECUTE ON proc_name TO role (or to user). Then you can add the user to the role.

A role is the set of GRANTs. You can GRANT right TO user without role.
--------
So, in SSMS go to Security and create NEW LOGIN
Right click on LOGIN - choose Properties
Set default database, language
Skip server role
Tab "Mapping"
Click on database to which you need the access
Fill User (default = login name), default schema (usually dbo)
Bottom table defines access you needed - choose as many roles as required
Click OK - it will create the user

Expand database --> Security --> Users
Right click on the user --> Properties
Fill parameters / choose options ----- You will see here many access options for the user for this database.