Get list of databases user has access to

前端 未结 3 840
春和景丽
春和景丽 2020-12-17 19:23

I have a SQL Server 2008 instance with several databases and I\'m currently writing a C# application to access those databases. In this app, the end user can select a databa

3条回答
  •  情深已故
    2020-12-17 19:51

    You can query all databases from sys.sysdatabases, and check if the user has access with HAS_DBACCESS:

    SELECT name
    FROM sys.sysdatabases
    WHERE HAS_DBACCESS(name) = 1
    

提交回复
热议问题