Description of the problem: after the SQL Server database backup is restored, the word "restricted access" appears after the database name
Problem two description: When restoring to a SQL Server database, prompt: System.Data.SqlClient.SqlError: Cannot obtain exclusive access to a database because the database is in use. (MICROSOFT.SQLSERVER.SMO). This problem occurs because another user is using the database when the database is restored. Restoring a database requires that the database work in Single-user mode. Typically, the DBA does not allow other users to connect to the database while it is operating.
Problem One solution:
Right-click the database-> properties-> option-> status-> restricted access-> Select multiple-> OK.
Problem Two solutions:
Method one (most convenient): Right-click the database-> properties-> option-> status-> restricted access-> select Single-> OK. and then restore.
Method two (most direct): Disconnect the database
Method III (Most violent): Logout/Restart the database server
Method four (most troublesome): Write code to modify the database related properties, although the trouble, sometimes still need to use, then use the time to study. Method V (End-level solution):
Critical SQL statements:
ALTER DATABASE [datebase] SET OFFLINE with ROLLBACK IMMEDIATE
Run out and then
ALTER database [Datebase] set online