Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
possible to back up a db in sql 2005 but it is not supporting in sql 2008

exception is showing
Backup failed for Server '\\.\pipe\6754F9F4-3FC4-42\tsql\query'. 
 this version is not supported

C#
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Microsoft.SqlServer.Management;
using Microsoft.SqlServer.Management.Smo;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Specialized;
using System.IO;
using Microsoft.SqlServer.Management.Common;



namespace ChequeText
{
    class BackupRestore : DBConnection
    {


        /// <summary>
        /// Backup the database
        /// </summary>
        internal void TakeBackUp()
        {
            //if(MessageConfirmation.MessageShowYesNo("Do you want to take back up?"))
            // if (MessageBox.Show("Do you want to take back up?", "My Soft", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            if (MessageBox.Show("Do you want to take back up?", "Bank", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                if (sqlcon.State == ConnectionState.Closed)
                {
                    sqlcon.Open();
                }
                string DBName = sqlcon.Database; ;
                string[] arr = DBName.Split('\\');
                DBName = arr[arr.Length - 1].Replace(".MDF", "");
                string DBFolder = arr[arr.Length - 2];
                ServerConnection  srvConn = new ServerConnection(sqlcon);
                SaveFileDialog saveBackupDialog = new SaveFileDialog();
                Server srvSql = new Server(srvConn);
                string path = Application.StartupPath + @"\Data\DBBankCheque.mdf";
                srvSql = new Server(srvConn);
                DateTime BackupDate = DateTime.Now;
                string BakDt = BackupDate.ToString("ddMMyyyhhmmss");
                string FName = "Bank---" + DBFolder + "-" + BakDt + ".bak";
                saveBackupDialog.FileName = FName;
                if (saveBackupDialog.ShowDialog() == DialogResult.OK)
                {
                    Backup bkpDatabase = new Backup();
                    bkpDatabase.Action = BackupActionType.Database;
                    bkpDatabase.Database = path;
                    BackupDeviceItem bkpDevice = new BackupDeviceItem(saveBackupDialog.FileName, DeviceType.File);
                    bkpDatabase.Devices.Add(bkpDevice);
                    try
                    {
                        bkpDatabase.SqlBackup(srvSql);

                       MessageBox.Show("The backup of database  completed successfully ", "Bank", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        //   MessageBoxes.messageBoxShow("The backup of database  completed successfully");

                    }
                    catch (Exception ex)
                    {
                       msgBox.Commen(ex.ToString() );
                       // MessageBox.Show("Backup failed for Server .  (Microsoft.SqlServer.Smo)", "Bank Software", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    finally
                    {
                        sqlcon.Close();
                    }
                }
            }
        }
Posted
Updated 9-Aug-12 19:51pm
v4

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