Check access to the database using HAS_DBACCESS – SQL Server
HAS_DBACCESS(): This function is used to check whether the user has access to the given database or not. This function returns an integer value 1 or 0 or null.
If the return value is 1 then the user has access to the database. If the return value is null then the function argument is invalid. If the return value is 0 then the user does not have access to the database or the database is offline or suspect or single user mode or other user is using the database.
HAS_DBACCESS ( ‘database_name’ )
1. Check access to the current database.