关于sql server:我关闭了SQL Connection,却无法打开它进行备份

I closed SQL Connection and Can't Open it back up

我使用此查询关闭了与SQL Server的所有连接(Windows身份验证)

1
ALTER DATABASE YourDb SET single_user WITH ROLLBACK immediate

现在我在Web应用程序上收到此错误

Cannot open database"DataCleanup" requested by the login. The login failed.
Login failed for user 'BIVAR\\DEV_WEB_VM$'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Cannot open database"DataCleanup" requested by the login. The login failed.
Login failed for user 'BIVAR\\DEV_WEB_VM$'.

源错误:

1
2
3
4
5
Line 91:                
Line 92:                 {
Line 93:                     sqlCon2.Open();
Line 94:                     {
Line 95:                         //PM3-PM5-PR

我不确定如何再次为所有人打开连接?


您必须首先明确连接到其他数据库。我建议使用[master]或[tempdb]。然后,您可以使用以下方式打开它进行备份:

1
ALTER DATABASE YourDb SET multi_user;

您当前遇到的问题可能是您没有明确指定数据库,因此数据库将使用默认值,这很可能是[YourDb]。如果该数据库已经存在一个连接(甚至来自您),那么您将无法建立连接。