Problem description: After a 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, Tip: System.Data.SqlClient.SqlError: Because the database is in use, you cannot gain exclusive access to the database. (MICROSOFT.SQLSERVER.SMO). This problem occurs because another user is using the database while the database is being restored. Restoring a database requires the database to 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 Database--Properties-----restricted access, state---Select multiple-OK.
Problem Two solutions:
Method one (most convenient): Right-click the database--Properties----state-----Select single-> OK. and then restore.
Method two (most direct): Disconnecting database connections
Method three (most violent): Log off/Restart the database server
Method Four (the most troublesome): Write code to modify the database related properties, although the trouble, sometimes still need to use, then use the time to study.
When you restore or delete a SQL Server 2008 database, the frequently-stewed occurrences are:
"Because the database is in use, you cannot gain exclusive access to the database", the Final solution is as follows
Key SQL statements:
ALTER DATABASE [datebase] SET OFFLINE with ROLLBACK IMMEDIATE
Run out and then
ALTER database [Datebase] set online
Unable to gain exclusive access to the database because the database is in use---Resolution to restore or delete the database