Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can take the database backup using SQL Server backup wizard or using SQL Server BackUp Database statement</p> <p>SQL Server Management Objects (SMO) is a collection of objects that are designed for programming all aspects of managing Microsoft SQL Server.</p> <p>For taking the database backup using C#, you have to add the following references in your application-</p> <pre><code>Microsoft.SqlServer.ConnectionInfo Microsoft.SqlServer.Management.Sdk.Sfc Microsoft.SqlServer.Smo Microsoft.SqlServer.SmoExtended Microsoft.SqlServer.SqlEnum </code></pre> <p>In your .CS file you will have to use the following namespaces-</p> <pre><code>using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Common; </code></pre> <p>After using above namespaces, write the following code to take the database backup-</p> <pre><code>public void BackupDatabase(string databaseName, string userName, string password, string serverName, string destinationPath) { //Define a Backup object variable. Backup sqlBackup = new Backup(); //Specify the type of backup, the description, the name, and the database to be backed up. sqlBackup.Action = BackupActionType.Database; sqlBackup.BackupSetDescription = "BackUp of:" + databaseName + "on" + DateTime.Now.ToShortDateString(); sqlBackup.BackupSetName = "FullBackUp"; sqlBackup.Database = databaseName; //Declare a BackupDeviceItem BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath + "FullBackUp.bak", DeviceType.File); //Define Server connection ServerConnection connection = new ServerConnection(serverName, userName, password); //To Avoid TimeOut Exception Server sqlServer = new Server(connection); sqlServer.ConnectionContext.StatementTimeout = 60 * 60; Database db = sqlServer.Databases[databaseName]; sqlBackup.Initialize = true; sqlBackup.Checksum = true; sqlBackup.ContinueAfterError = true; //Add the device to the Backup object. sqlBackup.Devices.Add(deviceItem); //Set the Incremental property to False to specify that this is a full database backup. sqlBackup.Incremental = false; sqlBackup.ExpirationDate = DateTime.Now.AddDays(3); //Specify that the log must be truncated after the backup is complete. sqlBackup.LogTruncation = BackupTruncateLogType.Truncate; sqlBackup.FormatMedia = false; //Run SqlBackup to perform the full database backup on the instance of SQL Server. sqlBackup.SqlBackup(sqlServer); //Remove the backup device from the Backup object. sqlBackup.Devices.Remove(deviceItem); } </code></pre> <p>Use SQL Server's Generate Scripts commend</p> <p>right click on the database; Tasks -> Generate Scripts</p> <ol> <li>select your tables, click Next</li> <li>click the Advanced button</li> <li>find Types of data to script - choose Schema and Data.</li> <li>you can then choose to save to file, or put in new query window.</li> <li>results in CREATE and INSERT statements for all table data selected in bullet 2.</li> </ol> <p><img src="https://i.stack.imgur.com/EyjOw.png" alt="see this image"></p>
    singulars
    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