重複の可能性:
データベースが使用中のため、排他アクセスを取得できませんでした
プロジェクトで C#、.net4、および SQL Server 2008 R2 を使用し、次のコードを使用してデータベースを復元します。
_comm = new SqlCommand("use master; RESTORE DATABASE [DB1] FROM DISK = @Address WITH RESTRICTED_USER, FILE = 1, NOUNLOAD, REPLACE, STATS = 10; use DB1;", _conn);
_comm.CommandType = System.Data.CommandType.Text;
_comm.Parameters.AddRange(new SqlParameter[]
{
new SqlParameter("@Address", _path)
});
_conn.Open();
_comm.ExecuteNonQuery();
次のエラーが表示されます。
データベースが使用中のため、排他アクセスを取得できませんでした。RESTORE DATABASE が異常終了しています。データベース コンテキストを「master」に変更しました。データベース コンテキストを「DB1」に変更しました。