tatarao25 0 Light Poster

hi evey one ,i written code in c# language to take sql server 2008 backup using Sumo objects
i am getting the error saying backup failed to [servername],the code is writen as following

try
            {
               
                sqlConn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
               
                sqlServer = new Server(new ServerConnection(sqlConn));
             
                 dbList = new List<Database>();
                foreach (Database db in sqlServer.Databases)
                {
                    dbList.Add(db);
                }

                cmbBackupDb.DataSource = dbList;
                //cmbRestoreDb.DataSource = dbList;

                //cmbBackupMode.SelectedIndex = 0;
              
            }
            catch (Exception exc)
            {
                MessageBox.Show(string.Format("Exception occured.\nMessage: {0}", exc.Message));
            }
onbackup Click:
 private void BackupDb()
        {
            dbName = ((Database)cmbBackupDb.SelectedItem).Name;
            Backup dbBackup = new Backup();

            try
            {
                dbBackup.Action = BackupActionType.Database;
               
                dbBackup.Database = dbName;
                //dbBackup.BackupSetName = string.Format("{0} backup set.", dbName);
                dbBackup.BackupSetDescription = string.Format("Database: {0}. Date: {1}.", dbName, DateTime.Now.ToString("dd.MM.yyyy hh:m"));
                dbBackup.MediaDescription = "Disk";
                dbBackup.BackupSetName = dbName;
              
                //bk.ExpirationDate = DateTime.Now.AddDays(30);
                dbBackup.LogTruncation = BackupTruncateLogType.Truncate;
                dbBackup.Initialize = true;
                dbBackup.FormatMedia = false;
                dbBackup.Initialize = true;
                dbBackup.Checksum = true;
                dbBackup.ContinueAfterError = true;
                dbBackup.Incremental = false;
              
                // Add the backup device to the backup

                BackupDeviceItem device = new BackupDeviceItem(saveBakFile.FileName, DeviceType.File);
                dbBackup.Devices.Add(device);

                //txtBackupSql.Text = dbBackup.Script(sqlServer);

                progBar.Visible = true;
                progBar.Value = 0;

                dbBackup.Complete += new ServerMessageEventHandler(dbBackup_Complete);
                dbBackup.PercentCompleteNotification = 10;
                dbBackup.PercentComplete += new PercentCompleteEventHandler(PercentComplete);
                dbBackup.SqlBackup(sqlServer);
            }
            catch (Exception exc)
            {
                dbBackup.Abort();
                MessageBox.Show(string.Format("Exception occured.\nMessage: {0}", exc.Message));
            }
            finally
            {
                sqlConn.Close();
            }

            progBar.Visible = false;
        }
  
        void PercentComplete(object sender, PercentCompleteEventArgs e)
        {
            if (progBar.Value < progBar.Maximum)
            {
                if ((progBar.Value + e.Percent) <= 100)
                {
                    progBar.Value += e.Percent;
                }
                else
                    progBar.Value = 100;
            }
        }

        void dbBackup_Complete(object sender, ServerMessageEventArgs e)
        {
            MessageBox.Show("Backup complete");
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.