Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL Server 2008 Login creation

Posted on 2014-04-09
4
Medium Priority
?
552 Views
Last Modified: 2014-04-09
Hello we created a login for 2 users with access to different database each other without one have access to the other database, in other words "USER A" just have access to database "A" and "USER B" just have access to database "B" and "USER A" and "USER B" must not have access to other database on the system. To create that 2 logins and permissions we made:

CREATE DATABASE A
GO
CREATE DATABASE B
GO
CREATE LOGIN user_A with password='U$er_A@1234'
Go
CREATE LOGIN user_B with password='U$er_B@1234'
Go
USE A
GO
CREATE USER user_A for login user_A;
GO
EXEC sp_addrolemember 'db_owner', 'user_A'
GO
USE B
GO
CREATE USER user_B for login user_B
GO
EXEC sp_addrolemember 'db_owner', 'user_B'

Open in new window


But when we we try to login with SQL Management Studio with "User A" or "User B" say login failed:

TITLE: Connect to Server
------------------------------

Cannot connect to 14933-71078.

------------------------------
ADDITIONAL INFORMATION:

Login failed for user 'xxx'. (Microsoft SQL Server, Error: 18456)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=18456&LinkId=20476

Open in new window


   Now in same SQL Managmenet Studio with main Windows Administration we go Security/Logins to "User A" or "User B" and in Properties/Server Roles is just checked for any of the 2 "public". We made a test on check all and after check all on any user enter perfect without the login error. The problem with check all is we need to know what to check for security reasons because we don´t want that 2 logins have access to "master" or any other database on the system just the assigned for each user and we need the access of "User A" or "User B" because we´ll use in a connection string in an asp application similar like:

connectionstring="Provider=SQLNCLI10.1; Persist Security Info=false; Data Source=server; Initial Catalog=database A; User Id=UserA;Password=xxx"

Open in new window


And check all options in roles for sure we are giving access to all, then what we need to check there? And like we have attempts of someone trying to enter the SQL we want only force like we say just "User A" just database "B" and "User B" just database "B" nothing else for them. And of course considering also that logins when we´ll use in the connection string must be able that uses to use our system good, is a school because our system when any student enter with his/her password our application record scoring, edit profile, etc.
I hope someone can help.
Thank you
0
Comment
Question by:coerrace
[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
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
Dulton earned 2000 total points
ID: 39989659
I believe you need something like the following.

/*Create User A and Database A*/

USE [master]
GO
CREATE DATABASE [A]
GO
CREATE LOGIN [user_A] with password='U$er_A@1234', default_database=[A]
GO
GRANT CONNECT SQL TO [user_A]
GO
USE [A]
GO
CREATE USER [user_A] for login [user_A];
GO
ALTER USER [user_A] with DEFAULT_SCHEMA=[dbo]
GO
EXEC sp_addrolemember 'db_owner', 'user_A'
GO

/*Create User B and Database B*/

USE [master]
GO
CREATE DATABASE [B]
GO
CREATE LOGIN [user_B] with password='U$er_B@1234', default_database=[B]
GO
GRANT CONNECT SQL TO [user_B]
GO
USE [B]
GO
CREATE USER [user_B] for login [user_B];
GO
ALTER USER [user_B] with DEFAULT_SCHEMA=[dbo]
GO
EXEC sp_addrolemember 'db_owner', 'user_B
GO

Open in new window

0
 

Author Comment

by:coerrace
ID: 39989680
The users update ok but they have access to "master" database is possible eliminate the access to "master" databse?
Thank you
0
 
LVL 6

Expert Comment

by:Dulton
ID: 39989710
I'm unable to find any way to limit it. My belief is that as long as you don't create them a user in master, they'll inherit the guest user... with minimal permission.

http://social.msdn.microsoft.com/Forums/sqlserver/en-US/058ef200-9aee-4e0c-b312-46852bb4dd7a/deny-access-to-master?forum=sqlsecurity
0
 

Author Comment

by:coerrace
ID: 39989952
Ok thank you anyway if you find a way to block post.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this article, we’ll look at how to deploy ProxySQL.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

597 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