gpt4 book ai didi

c# - 无法在事务内执行备份或还原操作。备份数据库异常终止

转载 作者:太空狗 更新时间:2023-10-29 22:05:36 24 4
gpt4 key购买 nike

我正在尝试在我的应用程序中执行 backUprestore 命令,它由 EF6 建模。

对于我的备份,我创建了一个 Sp,您可以在此处看到:

CREATE PROCEDURE GetBackUp
-- Add the parameters for the stored procedure here
@address nvarchar(max)
AS
BEGIN
BACKUP DATABASE [db-invoice-169] to DISK=@address
END
GO

在我的应用程序中,我称之为 Sp

 private void Backup_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
string str_filename = string.Empty;
sfd.FileName = "backup_database_" + DateTime.Now.ToShortDateString().Replace("/", "_");
sfd.Filter = @"backup files(*.bak)|*.bak|all files(*.*)|*.*";
sfd.FilterIndex = 1;
sfd.OverwritePrompt = true;
sfd.Title = "***save backup files***";
if (sfd.ShowDialog() == DialogResult.OK)
{
str_filename = sfd.FileName;
backup(str_filename);
}
}
private void backup(string str_filename)
{
try
{
this.Cursor = Cursors.WaitCursor;
db.Database.ExecuteSqlCommand(@"EXEC [dbo].[back_up] @address = N'"+str_filename+"'");
this.Cursor = Cursors.Default;
MessageBox.Show("عملیات پشتیبان گیری موفقیت آمیز بود");
}
catch (Exception ex)
{
MessageBox.Show("عملیات پشتیبان گیری موفقیت آمیز نبود |" + ex.Message);
}

}

但是我得到了这个错误:

Cannot perform a backup or restore operation within a transaction. BACKUP DATABASE is terminating abnormally.

最佳答案

尝试改变这一行:

db.Database.ExecuteSqlCommand(@"EXEC [dbo].[back_up] @address = N'"+str_filename+"'");

到:

db.Database.ExecuteSqlCommand(TransactionalBehavior.DoNotEnsureTransaction, @"EXEC [dbo].[back_up] @address = N'"+str_filename+"'");

阿布拉尔

关于c# - 无法在事务内执行备份或还原操作。备份数据库异常终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25310219/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com