Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
322 views
in Technique[技术] by (71.8m points)

sql server - Hide SQL database from Management Studio

How can you hide databases you do not have access rights to when logging into SQL Server 2005 / 2008?

Currently if a user connects, they see all the databases on the server, meaning they have to scan though the list to find their database.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

After hours of trying to figure out how to create a user account which only has access to 1 DB, and can only see that DB. I think i figured it out!!!!

  1. Create a user account ( make sure its not mapped to any Database, otherwise you will get the final error Msg 15110, Level 16, State 1 and note proposed solution)

    USE [master]
    GO
    CREATE LOGIN [us4] 
        WITH PASSWORD=N'123', 
        DEFAULT_DATABASE=[master], 
        CHECK_EXPIRATION=OFF, 
        CHECK_POLICY=OFF
    
  2. Right Click on the upper section of the SQL (SQLSERVER Name)>Properties>Permissions>Click on the user account, and select Deny to view databases.

    use [master]
    GO
    DENY VIEW ANY DATABASE TO [us4]
    
  3. Right Click on the newly created DB, Properties,Files, and change the Owner to the newly created account.(important note: ALTER ROLE [db_owner] ADD MEMBER [us4] does not work)

    USE [dbname]
    GO
    EXEC dbo.sp_changedbowner @loginame = N'us4', @map = false
    

At this point, once the user logs in he will see the Master,tempdb and will also see the new DB which he is a DB Owner of..You may want to go to Tools>Option and enabled the option to hide system objects so that you don't show the master,tempdb,etc. You may also need SP1 if this option does not work

Msg 15110, Level 16, State 1, Line 1
The proposed new database owner is already a user or aliased in the database.

proposed solution to Msg 15110: to resolve above error simply delete the user from database security node and try again

Hope that helps...

Nikhil


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...