Hide SQL DB's Users do Not have Access to

rr-4098 2,351 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
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories


8 answers

Sort by: Oldest
  1. Guoxiong 8,146 Reputation points
    2024-04-10T16:42:04.5066667+00:00

    In the Login Properties, you can map the user to the database(s) they should access to. For example, if you have three databases A, B and C, you want the user1 only to access to B, in the User Mapping of the Login Properties, you check the database B for that user and uncheck the other databases.

    Was this answer helpful?

    0 comments No comments

  2. Olaf Helper 47,631 Reputation points
    2024-04-10T17:17:42.98+00:00

    "View all DB's" is an "all or nothing"

    They still can change the context to an other database, but they "see" only the current database.

    Was this answer helpful?

    0 comments No comments

  3. rr-4098 2,351 Reputation points
    2024-04-10T17:21:54.25+00:00

    The test user account already had DB mapping. What is odd is they can see the Master and TempDB's. They cannot see their DB but can run queries against it. They need to see the DB since they do not know all the DB names. Is their any way to hide other DB names?

    Was this answer helpful?

    0 comments No comments

  4. Guoxiong 8,146 Reputation points
    2024-04-10T17:49:06.09+00:00

    Make sure the user has the right to view the databases:

    USE [master];  
    GO  
    GRANT VIEW ANY DATABASE TO [TestUser];
    GO
    

    Was this answer helpful?


  5. 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

    Was this answer helpful?


Your answer

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