From c79fbf5265c1cfbe01bf03b0e546dbbd9a4a5842 Mon Sep 17 00:00:00 2001 From: Kenneth Hsu Date: Sat, 19 Jan 2019 21:20:03 -0800 Subject: [PATCH] Dispose of connection after use. --- .../Server/WebServer/RESTMethods/Backups.cs | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Duplicati/Server/WebServer/RESTMethods/Backups.cs b/Duplicati/Server/WebServer/RESTMethods/Backups.cs index 4f412baaa..91c028013 100644 --- a/Duplicati/Server/WebServer/RESTMethods/Backups.cs +++ b/Duplicati/Server/WebServer/RESTMethods/Backups.cs @@ -127,21 +127,22 @@ namespace Duplicati.Server.WebServer.RESTMethods Serializable.ImportExportStructure importedStructure = Backups.LoadConfiguration(configurationFile, importMetadata, getPassword); // This will create the Duplicati-server.sqlite database file if it doesn't exist. - Duplicati.Server.Database.Connection connection = Program.GetDatabaseConnection(advancedOptions); - - if (connection.Backups.Any(x => x.Name.Equals(importedStructure.Backup.Name, StringComparison.OrdinalIgnoreCase))) + using (Duplicati.Server.Database.Connection connection = Program.GetDatabaseConnection(advancedOptions)) { - throw new InvalidOperationException($"A backup with the name {importedStructure.Backup.Name} already exists."); - } + if (connection.Backups.Any(x => x.Name.Equals(importedStructure.Backup.Name, StringComparison.OrdinalIgnoreCase))) + { + throw new InvalidOperationException($"A backup with the name {importedStructure.Backup.Name} already exists."); + } - string error = connection.ValidateBackup(importedStructure.Backup, importedStructure.Schedule); - if (!string.IsNullOrWhiteSpace(error)) - { - throw new InvalidOperationException(error); - } + string error = connection.ValidateBackup(importedStructure.Backup, importedStructure.Schedule); + if (!string.IsNullOrWhiteSpace(error)) + { + throw new InvalidOperationException(error); + } - // This creates a new ID and DBPath. - connection.AddOrUpdateBackupAndSchedule(importedStructure.Backup, importedStructure.Schedule); + // This creates a new ID and DBPath. + connection.AddOrUpdateBackupAndSchedule(importedStructure.Backup, importedStructure.Schedule); + } return importedStructure; }