简体   繁体   English

SMO 备份失败,错误 1827(完整数据库)

[英]SMO Backup fails with error 1827 (full database)

I am using an SqlExpress 2012 (I have to, no other choice).我正在使用 SqlExpress 2012(我必须这样做,别无选择)。

The database runs full under some rare circumstances.在极少数情况下,数据库会满载。
Now I want to make a backup of the full database and then truncate some tables and shrink back the database.现在我想备份整个数据库,然后截断一些表并收缩数据库。 For the backup I use the following code:对于备份,我使用以下代码:

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));
}

But if I do that, I get an error after some time.但是,如果我这样做,一段时间后我会收到错误消息。 This is my error log:这是我的错误日志:

2020-01-20 13:42:54.89 spid10s Starting up database 'msdb'. 2020-01-20 13:42:54.89 spid10s 启动数据库“msdb”。
2020-01-20 13:42:54.90 spid12s Starting up database 'mssqlsystemresource'. 2020-01-20 13:42:54.90 spid12s 启动数据库“mssqlsystemresource”。
2020-01-20 13:42:54.91 spid12s The resource database build version is 12.00.6108. 2020-01-20 13:42:54.91 spid12s 资源库构建版本为 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:54.93 spid12s 启动数据库“模型”。
2020-01-20 13:42:55.69 spid12s Clearing tempdb database. 2020-01-20 13:42:55.69 spid12s 清除 tempdb 数据库。
2020-01-20 13:43:00.07 spid12s Starting up database 'tempdb'. 2020-01-20 13:43:00.07 spid12s 启动数据库“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 Service Broker 端点处于禁用或停止状态。
2020-01-20 13:43:00.37 spid18s The Database Mirroring endpoint is in disabled or stopped state. 2020-01-20 13:43:00.37 spid18s 数据库镜像端点处于禁用或停止状态。
2020-01-20 13:43:00.39 spid18s Service Broker manager has started. 2020-01-20 13:43:00.39 spid18s Service Broker 管理器已启动。
2020-01-20 13:43:01.02 spid10s Recovery is complete. 2020-01-20 13:43:01.02 spid10s 恢复完成。 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:02.66 服务器公共语言运行时 (CLR) 功能使用来自 C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319 的 CLR 版本 v4.0.30319 初始化。
2020-01-20 13:43:15.65 spid51 Starting up database 'TESTDB'. 2020-01-20 13:43:15.65 spid51 启动数据库“TESTDB”。
2020-01-20 13:43:36.75 spid51 Error: 1827, Severity: 16, State: 1. 2020-01-20 13:43:36.75 spid51 错误:1827,严重性:16,状态: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:43:36.75 spid51 CREATE DATABASE 或 ALTER DATABASE 失败,因为由此产生的累积数据库大小将超过每个数据库 10240 MB 的许可限制。
2020-01-20 13:49:04.59 Backup Error: 3041, Severity: 16, State: 1. 2020-01-20 13:49:04.59 备份错误:3041,严重性:16,状态:1。
2020-01-20 13:49:04.59 Backup BACKUP failed to complete the command BACKUP DATABASE PHASIS. 2020-01-20 13:49:04.59 备份 BACKUP 未能完成命令 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 备份错误:3041,严重性:16,状态:1。
2020-01-20 14:14:56.76 Backup BACKUP failed to complete the command BACKUP DATABASE PHASIS. 2020-01-20 14:14:56.76 备份 BACKUP 未能完成命令 BACKUP DATABASE PHASIS。 Check the backup application log for detailed messages.检查备份应用程序日志以获取详细消息。

It seems to me that the spid51 tries to do a "CREATE DATABASE" after collecting all infos.在我看来,spid51 在收集所有信息后尝试执行“创建数据库”。 But then it tries to make the backup file as part of the server instance and that crashes because the 10 GB cannot increase anymore.但随后它尝试将备份文件作为服务器实例的一部分,并且由于 10 GB 无法再增加而崩溃。

Has someone an idea on how to alter the backup, so that the backup is not counted anymore against the database limit?有人知道如何更改备份,以便备份不再计入数据库限制吗? Maybe explicitly give it a new database or something the like?也许明确地给它一个新的数据库或类似的东西?

The infos of Microsoft regarding the SMO is not really helpful: https://docs.microsoft.com/de-de/dotnet/api/microsoft.sqlserver.management.smo.backup?redirectedfrom=MSDN&view=sql-smo-140.17283.0微软关于 SMO 的信息并不是很有帮助: https : //docs.microsoft.com/de-de/dotnet/api/microsoft.sqlserver.management.smo.backup? redirectedfrom=MSDN&view=sql-smo-140.17283 。 0

edit: When I do a backup with the Management Studio it works, but I have to do it with smo programmatically.编辑:当我使用 Management Studio 进行备份时,它可以工作,但我必须以编程方式使用 smo 进行备份。

Ok, that is... erm... a little bit embarassing.好吧,那是……呃……有点尴尬。
I raised the timeout from 360 (6 minutes) to 3600 (60 minutes) and it didn't crash anymore.我将超时从 360(6 分钟)提高到 3600(60 分钟)并且它不再崩溃了。 So the log entries and error messages were only really confusing and lead me astray.所以日志条目和错误消息真的很混乱,让我误入歧途。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM