sql 2008中数据库备份失败 [英] data base back up failed in sql 2008

查看:106
本文介绍了sql 2008中数据库备份失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试备份我的数据库时,然后显示错误Microsoft.SqlServer.Smo"



下面我用过的代码

when i try to back up my db then showing "error Microsoft.SqlServer.Smo"



below code i used

internal void TakeBackUp()
        {
            //if(MessageConfirmation.MessageShowYesNo("Do you want to take back up?"))
            // if (MessageBox.Show("Do you want to take back up?", "A2zSchool", 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)
                    {
                        MessageBox.Show("Backup failed for Server .  (Microsoft.SqlServer.Smo)", "Bank Software", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    finally
                    {
                        sqlcon.Close();
                    }
                }
            }
        }


索引超出数组


index out of array

推荐答案

这是草率的代码.使用System.IO.Path类更改扩展名和文件路径.

设置一个断点并检查您的异常是否包含内部异常.底部的一个告诉您真正的错误.
This is sloppy code. Use the System.IO.Path class to change extensions and file paths.

Set a break point and examine your exception for inner exceptions. The bottom one tells you the real error.


这篇关于sql 2008中数据库备份失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆