本帖最后由 hero515435 于 2014-11-20 09:35:44 编辑

解决方案 »

  1.   

    参考: WPF C#开发中利用SQLDMO进行数据库备份还原操作中的注意点
      

  2.   

    这是我的备份代码,没有出现你的问题        public bool BackUPDB(string strDbName, string strFileName, string ServerName, string UserName, string Password)
            {
                try
                {
                    SQLDMO.SQLServer svr = new SQLDMO.SQLServerClass();                svr.Connect(ServerName, UserName, Password);
                    SQLDMO.Backup bak = new SQLDMO.BackupClass();
                    bak.Action = 0;
                    bak.Initialize = true;
                    SQLDMO.BackupSink_PercentCompleteEventHandler pceh = new SQLDMO.BackupSink_PercentCompleteEventHandler(Step);
                    bak.PercentComplete += pceh;
                    bak.Files = strFileName;//这里可以写成路径+文件名形式,自己写!
                    bak.Database = strDbName;
                    bak.SQLBackup(svr);
                    svr.DisConnect();                using (System.IO.StreamWriter sw = new System.IO.StreamWriter(@"d:\AutoDbBackUpServiceLog\SucceedLog.txt", true))
                    {
                        sw.WriteLine(System.DateTime.Now.ToString() + ":" + "数据库["+ strDbName + "]执行成功!");
                    }
                    return true;
                }
                catch (Exception ex)
                {
                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(@"d:\AutoDbBackUpServiceLog\ErrorLog.txt", true))
                    {
                        sw.WriteLine(System.DateTime.Now.ToString()+":"+ex.Message);
                    }
                    return false;
                }
            }