Hide SQL DB's Users do Not have Access to

rr-4098 2,051 Reputation points
2024-04-10T15:43:00.6166667+00:00

I know I can set the permission to Deny "View all DB's" but I need users who are mapped to their DB's to be able to see them in SSMS. Thoughts?

SQL Server Other
{count} votes

Accepted answer
  1. Anonymous
    2024-04-17T09:54:46.8633333+00:00

    Hi @rr-4098,

    Do you mean how to change the exiting database into contained database? I did the test below:

    1. This is my database named aaa: User's image Please don't forget change it into partial:User's image
    2. Create a new login with password:
         create login TestC with password='test'
         
      
    3. Create a new user for the new login:
         use aaa
         Create user LUCY FOR login TestC with Default_schema=[dbo]
         
      
    4. You can check it:
         select * from master.sys.server_principals where name = 'TestC'
         
      
         select * from aaa.sys.database_principals where name= 'LUCY'
         
      
      2
    5. Change into contained database:
         Use aaa
         GO
         sp_migrate_user_to_contained
             @username = N'LUCY',
             @rename = N'keep_name',
             @disablelogin = N'do_not_disable_login';
         
      
      3
    6. Use SSMS to connect: You can enter the database name manually!!!
    7. 4
    0 comments No comments

7 additional answers

Sort by: Most helpful
  1. Anonymous
    2024-04-11T03:23:12.73+00:00

    Hi @rr-4098,

    Thanks for your information.

    Here is my database for test.

    User's image

    I checked the database properties, it has my domain\user account as the owner, because I created it.

    User's image

    Then I created a Test account with login to allow me to connect into SQL Server (Using SQL Authentication and the Test login)

    User's image

    During I created the account, I Use the server level login (Test) to set its Mappings to include the Test database.

    User's image

    Here you can see what my Test sees at the server level (everything) while it throws an error if I try to access any database.

    User's image

    However, when Test tries to access a database that it is mapped to, it can see the objects inside that database that have been granted to it under database user's Securable permissions.

    User's image

    Please feel free to share the issue more detailed here If you have any other questions, thank you.

    Best regards,

    Lucy Chen


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    https://docs.microsoft.com/en-us/answers/support/email-notifications


  2. rr-4098 2,051 Reputation points
    2024-04-11T18:18:17.6533333+00:00

    Thank you for the feedback. I did the same steps as you. The user can only access the DB they have access to and get errors on the other DB's. The problem is we do not want to user the "see" the other DB's. Please note, when I deny "view all db's" they can still query the DB, but need to see it since they are not sure of all the table names.


  3. rr-4098 2,051 Reputation points
    2024-04-12T14:23:02.38+00:00

    If a user is now a owner of a DB, doesn't this mean they have full rights to the DB? If this is the case this will be a problem.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.