Avatar of Dennis_Gundersen
Dennis_Gundersen asked on

How to define a user in MS SQL Server 2012 that can import data into Excel, but nothing more

I need to setup a user in SQL Server 2012 that can download data into Excel 2013 PowerPivot. It seems that it's not possible to completely hide the connection string in Excel, so it's important that the user has the absolute minimum of rights on the server instance and database as the Excel workbook will be shared. Would appreciate any good suggestions.

TIA
Dennis
Microsoft SQL Server

Avatar of undefined
Last Comment
Dennis_Gundersen

8/22/2022 - Mon
PadawanDBA

Would read only on the database that they are pivoting from count as absolute minimum rights?  They would be able to log in to the instance and read from the database you give them access to.  If yes, you would assign their login to the db_datareader role (in user mapping section of the login properties window) for that specific database.

Edit: If this is something that you anticipate needing to do again in the future, I would recommend an AD security group be granted these permissions, that way you only need to manage group membership from AD.
ASKER
Dennis_Gundersen

This Excel sheet has to be shared on a website, so AD isn't an option. I've already given the user db_datareader and SELECT right, but I really don't like the idea of unknown people being able to log on to the instance and view other databases, so I have was hoping reading data and logging in using SSMS could be split (don't have a firm understanding of the difference between login and user I'm afraid).

Re
D
QuinnDex

As PadawanDBA explained in his answer

you would assign their login to the db_datareader role (in user mapping section of the login properties window) for that specific database.

Permissions are granted for that database only, your users wouldnt be able to access other databases
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER
Dennis_Gundersen

Excellent, thanks!

Re
D
ASKER CERTIFIED SOLUTION
PadawanDBA

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Dennis_Gundersen

With the deny view database it should work out well. These people are my friends, but I use other databases too that they don't need to see, and an Excel sheet can show up in a Google search, so better safe than sorry.

Re
D
ASKER
Dennis_Gundersen

I'm still missing something. I added a new user with
USE [master]
GO
CREATE LOGIN [ReadOnlyUser] WITH PASSWORD=N'Admin1234', DEFAULT_DATABASE=[Test], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
USE [Test]
GO
CREATE USER [ReadOnlyUser] FOR LOGIN [ReadOnlyUser]
GO
USE [Test]
GO
ALTER ROLE [db_datareader] ADD MEMBER [ReadOnlyUser]
GO
DENY VIEW ANY DATABASE TO [ReadOnlyUser]
GO

But when I log in with that user, I can't see the Test database.

Re
D
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
Dennis_Gundersen

Never mind, I just forgot to include
use [Test]
GO
GRANT SELECT TO [ReadOnlyUser]
GO

It works great now. Only the Test database shows up in Excel and and nothing shows up in SSMS, but the user can still query that one database.

Re
D
PadawanDBA

Can you take a quick peek at the login for ReadOnlyUser ( Security > Logins > Right click 'ReadOnlyUser' > Properties > Securables > Permissions for <servername here> section) and tell me what it says next to View any database?  Also check in the user mapping tab, what are the permissions for the test database ?
PadawanDBA

Good to hear!
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER
Dennis_Gundersen

Securables: View any database, Grantor: sa, Deny

User Mapping: Database: Test, User: ReadOnlyUser, Default Schema: dbo, Membership: db_datareader and public

Re
D
QuinnDex

i think the points should have gone to PadawanDBA
ASKER
Dennis_Gundersen

Oops, didn't notice that I clicked the wrong link. I agree, but don't know how to change this.

Re
D
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
QuinnDex

Ask a moderator to change it
ASKER
Dennis_Gundersen

Seems I can't add a request attention call as PadawanDBA has already done so.

Moderators: I meant to give the points to PadawanDBA, but I clicked the wrong acceptance link by mistake. Sorry.
PadawanDBA

I mentioned it in the request, but I am perfectly fine with a point split as QuinnDex clarified for you in a timely manner.  I'm just happy we were able to help you get things setup in a manner that works for your requirements.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER
Dennis_Gundersen

No, you deserve the points, I was just a bit too quick and clicked the first green link as I scrolled my way up the page to accept the solution.

Re
D