#region Using directives using Microsoft.SqlServer.Management.Smo; // Allow shorthand notation #endregion namespace SqlBackup { class Program { static void Main(string[] args) { string db = «AdventureWorks»; // Define and set a variable Backup bck = new Backup(); // Instantiate a Backup object bck.Action = BackupActionType.Database; // Set Action property bck.BackupSetName = db + «_BackupSet»; // Set BackupSetName property bck.Database = db; // Set Database name property bck.DeviceType = DeviceType.File; // Set DeviceType property // Add method adds file to Devices collection // Must escape the backslash in C# bck.Devices.Add(«C:» + db + «.bak»); // Instantiate a Server object and // invoke Backup object?s SqlBackup method bck.SqlBackup(new Server()); } } }