Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i have no idea on how to backup data from database which is developed in SqlExpress.
please give steps to do this.
thanking you.
Posted

If you want Auto Backup:

Steps:
1. Create a SQL file with following content:

Set @BkpPath='[backup file path].bak'
BACKUP DATABASE [DBName] TO DISK = @BkpPath WITH FORMAT;

2. Create Schedule Task (from Control Panel) and put following text

in RUN : "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" -i"[sql file path].sql"
in Start in : "C:\Program Files\Microsoft SQL Server\100\Tools\Binn"
 
Share this answer
 
v4
right click on the Database ,go to task , click on backup, add destination path,click ok......
 
Share this answer
 
I have just used this code in my Project:
C#
private void DatabaseBackup()
        {
            string strDate = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString().PadLeft(2, '0') + DateTime.Now.Day.ToString().PadLeft(2, '0');
            string[] strTime = DateTime.Now.TimeOfDay.ToString().Split(':');
            string strDateTime = strDate + " " + strTime[0].PadLeft(2, '0') + strTime[1].PadLeft(2, '0');
            try
            {
                string backupPath = txtBackupLocation.Text.Trim() + "\\" + strDateTime + ".bak";
                int retVal = 0;
                retVal = _settingManager.DatabaseBackup(backupPath);
                if (retVal != 0)
                {
                    btnBackupDatabase.Enabled = false;
                    lblBackupStatus.Text = "Database backup successful.";
                    MessageBox.Show("The backup of database completed successfully." + Environment.NewLine + backupPath, Program.MESSAGEBOXTITLE, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    btnClose.Focus();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error [Database Backup]: " + Environment.NewLine + ex.Message, Program.MESSAGEBOXTITLE, MessageBoxButtons.OK, MessageBoxIcon.Error);
                lblBackupStatus.Text = "Database backup failed.";
            }
        }


For more have look on: SQL Server 2005 Database Backup and Restore using C# and .NET 2.0[^]
http://midnightprogrammer.net/post/BackupRestore-SQL-database-using-C.aspx[^]
 
Share this answer
 
Comments
Herman<T>.Instance 15-Mar-12 9:39am    
small tip:string strDate = DateTime.Now.ToString("yyyyMMdd HHmm");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900