Solved

GRANT SQL User Database Read Only

Posted on 2012-03-13
4
534 Views
Last Modified: 2012-03-14
Hello,

I recently created a new SQL user on a SQL 2000 and SQL 2008 default instances on separate servers. Now I need to grant read only access to selected databases for that user. I'm having a little trouble putting togehter the SQL syntax for each version.

Can someone help me out with this?

Thank you in advance!
0
Comment
Question by:e_rock
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 37718040
Something like this should work:
EXEC sp_addrolemember 'db_datareader', 'yourusername'
0
 

Author Comment

by:e_rock
ID: 37719670
acperkins - I tried that and this is what i'm getting. Steps are as follows:

1. I created the user by using the statement and pointing it to the database:
     CREATE LOGIN username WITH Password = 'password'        

2. I then ran the statement you provided pointing to the same database:
      EXEC sp_addrolemember 'db_datareader', 'username'

and i get the following message:
       
Msg 15410, Level 11, State 1, Procedure sp_addrolemember, Line 75
User or role 'test12' does not exist in this database.

I have verified that the user i created exist under Security.

Thanks.
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 250 total points
ID: 37721045
EXEC master.dbo.sp_addlogin 'loginname', 'password', 'default_db' --for a SQL login
--EXEC sp_grantlogin 'login' --for a Windows login


EXEC db_name.dbo.sp_adduser 'loginname', 'loginname'
EXEX db_name.dbo.sp_addrolemember 'db_datareader', 'loginname'

OR of course:


USE db_name

EXEC dbo.sp_adduser 'loginname', 'loginname'
EXEX dbo.sp_addrolemember 'db_datareader', 'loginname'
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 37721531
I tried that and this is what i'm getting.
I am sorry I thought you just wanted to a User to a database role, I did not realize you had not even created the Login, let alone the User.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

734 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