Getting all databases which a sql logon can connect I need to know all databases in a SQL Server on which a user can connect. With sys.databases I get all databases and with sys.server_principals or sys.syslogins I get all server logons. But I can't find a table which contains a connection between these tables. Has anyone an idea how to solve this? Thanks.
You should be able to do something like this:

EXECUTE AS login = 'loginname';

SELECT name
FROM sys.databases
WHERE HAS_DBACCESS(name) = 1;

REVERT;


For reference see EXECUTE AS and HAS_DBACCESS