Hiding databases for a login on Microsoft Sql Server 2008R2 and above

Omgee Cares picture Omgee Cares · Jan 2, 2013 · Viewed 13.4k times · Source

Please can anyone assist with hiding the available databases on sql server 2008R2 or newer versions.

I have a new login user that I mapped to a specific database. When logging in with the specific login user I can see all the databases on the server, although I cannot access them except for the one I mapped to the login.

This is 100% but my problem is that I do not want the login to even see that those other databases are available.

How do I prevent those other databases that are not mapped to the login from displaying?

Answer

Raj picture Raj · Jan 2, 2013
USE master;
GO
DENY VIEW ANY DATABASE TO [newlogin]; 
GO
USE yourDB;
GO
DROP USER newlogin;
GO
USE master;
GO
ALTER AUTHORIZATION ON DATABASE::yourDB TO [newlogin];
GO

Raj