SQL 恢复失败,并显示“数据库已打开,一次只能有一个用户”
Summary: 为用户访问数据库时 SQL 数据库还原失败提供解决方案的知识库 (KB) 文章。
This article applies to
This article does not apply to
This article is not tied to any specific product.
Not all product versions are identified in this article.
Symptoms
SQL 数据库恢复到原始位置失败,并显示如下错误:
avsql Error <40258>: sqlconnectimpl_smo::get_database_data_names Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. ---> System.Data.SqlClient.SqlException: Database 'Avamar1' is already open and can only have one user at a time.
Cause
一个或多个用户或连接正在访问要恢复到的数据库。如果有用户或连接访问原始数据库,则无法覆盖该数据库。
Resolution
将数据库的状态从多用户模式更改为单用户模式。
使用 SQL Server Management Studio
要将数据库设置为单用户模式,请执行以下作:
-
在对象资源管理器中,连接到 SQL Server 数据库引擎的实例,然后展开该实例。
-
右键单击要更改的数据库,然后单击“属性”。
-
在“数据库属性”对话框中,单击“选项”页。
-
从限制访问选项中,选择单个。
-
如果其他用户已连接到数据库,则会显示“打开连接”消息。要更改属性并关闭所有其他连接,请单击是。
使用 Transact-SQL
要将数据库设置为单用户模式,请执行以下作:
-
连接到数据库引擎。
-
从“Standard”栏中,单击“New Query”。
-
将以下示例复制并粘贴到查询窗口中,然后单击“Execute”按钮。本示例将数据库设置为
SINGLE_USER模式以获取独占访问权限。然后,该示例将 Avamar1 数据库的状态设置为READ_ONLY并将对数据库的访问权限归还给所有用户。终止选项WITH ROLLBACK IMMEDIATE在第一个ALTER DATABASE陈述。这会导致回滚所有未完成的事务,并立即断开与 Avamar1 数据库的任何其他连接。
SQLCopy
USE master; GO ALTER DATABASE Avamar1 SET SINGLE_USER WITH ROLLBACK IMMEDIATE; GO ALTER DATABASE Avamar1 SET READ_ONLY; GO ALTER DATABASE Avamar1 SET MULTI_USER; GO
参考:
https://docs.microsoft.com/en-us/sql/relational-databases/databases/set-a-database-to-single-user-mode?view=sql-server-2017完成后,重试 SQL 数据库还原到原始位置。
Affected Products
AvamarProducts
Avamar, Avamar Plug-in for SQLArticle Properties
Article Number: 000038587
Article Type: Solution
Last Modified: 11 Dec 2025
Version: 5
Find answers to your questions from other Dell users
Support Services
Check if your device is covered by Support Services.