Hello @Jigar Zanzarukiya ,
The HAS_DBACCESS function checks several conditions to determine if a user has access to a specified database. Here are the key points it considers:
- Database State: The database must not be offline or in a suspect state.
- User Mapping: The user must be mapped to a login that has access to the database.
- Database Mode: The database should be in multi-user mode, or if in single-user mode, the current user must be the single user. In restricted-user mode, the user must be a member of the dbcreator or sysadmin fixed server roles, or the db_owner fixed database role.
If these conditions are met, HAS_DBACCESS returns 1, indicating the user has access. Otherwise, it returns 0 or NULL if the database name is invalid.
Please check these conditions whether users meet?
Below query will list all the database the current logged in user has access to:
SELECT name, HAS_DBACCESS(name) HasAccess
FROM sys.databases