Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have been using the code below for back up, try this.</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Common; using System.Data.SqlClient; using System.Configuration; using System.Data; /// &lt;summary&gt; /// Backups the data base. /// &lt;/summary&gt; /// &lt;param name="fileName"&gt;Name of the file.&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; public bool BackupDataBase(string fileName) { if (string.IsNullOrEmpty(fileName)) return false; bool isDatabackedUp = true; try { Backup sqlBackup = new Backup(); sqlBackup.Action = BackupActionType.Database; sqlBackup.BackupSetDescription = "ArchiveDataBase:" + DateTime.Now.ToShortDateString(); sqlBackup.BackupSetName = "Archive"; BackupDeviceItem deviceItem = new BackupDeviceItem(fileName, DeviceType.File); ServerConnection connection = new ServerConnection(this.BackupConnection); DataConnection dataConnection = new DataConnection(); Server sqlServer = new Server(dataConnection.ServerName); Database db = sqlServer.Databases[dataConnection.DataBaseName]; sqlBackup.Database = dataConnection.DataBaseName; sqlBackup.Initialize = true; sqlBackup.Checksum = true; sqlBackup.ContinueAfterError = true; sqlBackup.Devices.Add(deviceItem); sqlBackup.Incremental = false; sqlBackup.ExpirationDate = DateTime.Now.AddDays(3); sqlBackup.LogTruncation = BackupTruncateLogType.Truncate; sqlBackup.FormatMedia = false; sqlBackup.SqlBackup(sqlServer); return isDatabackedUp; } catch (Exception) { return false; } } private SqlConnection BackupConnection { get { string backupConnectionString = string.Empty; ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["LibrarySystemBackUpConnection"]; backupConnectionString = settings.ConnectionString; SqlConnection backupDatabaseConnection = new SqlConnection(backupConnectionString); return backupDatabaseConnection; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload