SQL 還原失敗,並顯示「資料庫已開啟,一次只能有一個使用者」

Summary: 知識庫 (KB) 文章,提供使用者存取資料庫時 SQL 資料庫還原失敗的解決方案。

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

將資料庫設定為單使用者模式:

  1. 對象資源管理器中,連接到 SQL Server 資料庫引擎的實例,然後展開該實例。

  2. 右鍵按下要更改的資料庫,然後按下「屬性」。

  3. 在「資料庫屬性」對話框中,按兩下「選項」 頁。

  4. 限制存取選項中,選取單一

  5. 如果其他使用者已連接到資料庫,則會顯示「打開連接」 消息。若要更改屬性並關閉所有其他連接,請按下“是”。

 

使用 Transact-SQL

將資料庫設定為單使用者模式:

  1. 連接到資料庫引擎。

  2. 在“標準”欄中,按兩下“新建查詢”。

  3. 將下列範例複製並貼到查詢視窗中,然後按一下「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

Avamar

Products

Avamar, Avamar Plug-in for SQL
Article 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.