Get list of databases user has access to

前端 未结 3 836
春和景丽
春和景丽 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:49

    You can use the system stored procedure sp_helplogins 'User Name'

    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2020-12-17 19:56

    Maybe as an alternative to Andomars answer (which I like!) you could interrogate Active Directory to see if the user is a member of a valid group for your database. I suspect this would mean you would have to maintain some Windows Group to Database Name lookup.

    0 讨论(0)
提交回复
热议问题