private void BackupSqlServerDB(string BackupPath, string DBName, string DBCon) { SqlConnection Con = new SqlConnection(); try { System.DateTime TheTime = DateTime.Now; string fileName = DBName + ".bak"; BackupPath = Path.Combine(BackupPath, fileName); if (System.IO.File.Exists(BackupPath)) System.IO.File.Delete(BackupPath); if (System.IO.File.Exists(BackupPath + ".zip")) System.IO.File.Delete(BackupPath + ".zip"); Con.ConnectionString = DBCon; Con.Open(); SqlCommand Cmd = new SqlCommand(); Cmd.Connection = Con; Cmd.CommandText = "BACKUP DATABASE " + DBName + " TO DISK ='" + BackupPath + "';"; Cmd.CommandTimeout = 360; Cmd.ExecuteNonQuery(); Cmd.Dispose(); Con.Close(); Con.Dispose(); GC.Collect(); } catch (Exception ex) { AddLog(ex.Message, "Preparing Sql Backup", true); } finally { Con.Close(); Con.Dispose(); GC.Collect(); } }
SqlConnection.ClearAllPools();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)