gpt4 book ai didi

c# - SMO 备份失败并出现错误 1827(完整数据库)

转载 作者:行者123 更新时间:2023-12-02 04:11:26 27 4
gpt4 key购买 nike

我正在使用 SqlExpress 2012(我必须这样做,别无选择)。

在极少数情况下,数据库会满载。
现在我想备份整个数据库,然后截断一些表并收缩数据库。对于备份,我使用以下代码:

public void BackupDatabase(string backupFilePath, string databaseServer, string databaseName, out string errorMessage)
{
var connection = new ServerConnection(databaseServer);
connection.StatementTimeout = 360;
Backup backup = new Backup();
backup.Devices.AddDevice(backupFilePath, DeviceType.File);
backup.Database = databaseName;
backup.Initialize = true;
backup.Incremental = false;
backup.Action = BackupActionType.Database;
backup.SqlBackup(new Server(connection));
}

但是如果我这样做,一段时间后我会收到错误消息。这是我的错误日志:

2020-01-20 13:42:54.89 spid10s Starting up database 'msdb'.
2020-01-20 13:42:54.90 spid12s Starting up database 'mssqlsystemresource'.
2020-01-20 13:42:54.91 spid12s The resource database build version is 12.00.6108. This is an informational message only. No user action is required.
2020-01-20 13:42:54.93 spid12s Starting up database 'model'.
2020-01-20 13:42:55.69 spid12s Clearing tempdb database.
2020-01-20 13:43:00.07 spid12s Starting up database 'tempdb'.
2020-01-20 13:43:00.37 spid18s The Service Broker endpoint is in disabled or stopped state.
2020-01-20 13:43:00.37 spid18s The Database Mirroring endpoint is in disabled or stopped state.
2020-01-20 13:43:00.39 spid18s Service Broker manager has started.
2020-01-20 13:43:01.02 spid10s Recovery is complete. This is an informational message only. No user action is required.
2020-01-20 13:43:02.66 Server Common language runtime (CLR) functionality initialized using CLR version v4.0.30319 from C:\Windows\Microsoft.NET\Framework64\v4.0.30319.
2020-01-20 13:43:15.65 spid51 Starting up database 'TESTDB'.
2020-01-20 13:43:36.75 spid51 Error: 1827, Severity: 16, State: 1.
2020-01-20 13:43:36.75 spid51 CREATE DATABASE or ALTER DATABASE failed because the resulting cumulative database size would exceed your licensed limit of 10240 MB per database.
2020-01-20 13:49:04.59 Backup Error: 3041, Severity: 16, State: 1.
2020-01-20 13:49:04.59 Backup BACKUP failed to complete the command BACKUP DATABASE PHASIS. Check the backup application log for detailed messages.
2020-01-20 14:14:56.76 Backup Error: 3041, Severity: 16, State: 1.
2020-01-20 14:14:56.76 Backup BACKUP failed to complete the command BACKUP DATABASE PHASIS. Check the backup application log for detailed messages.

在我看来,spid51 在收集所有信息后尝试执行“创建数据库”。但随后它尝试将备份文件作为服务器实例的一部分,但由于 10 GB 无法再增加而崩溃。

有人知道如何更改备份,以便备份不再计入数据库限制吗?也许明确地给它一个新的数据库或类似的东西?

微软关于 SMO 的信息并没有多大帮助:https://learn.microsoft.com/de-de/dotnet/api/microsoft.sqlserver.management.smo.backup?redirectedfrom=MSDN&view=sql-smo-140.17283.0

编辑:当我使用 Management Studio 进行备份时,它可以工作,但我必须以编程方式使用 smo 进行备份。

最佳答案

好吧,那是...呃...有点尴尬。
我将超时从 360(6 分钟)提高到 3600(60 分钟),它不再崩溃了。因此,日志条目和错误消息确实令人困惑,并让我误入歧途。

关于c# - SMO 备份失败并出现错误 1827(完整数据库),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59824549/

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