日期:2014-05-18  浏览次数:20532 次

.NET用SQLDMO 备份数据库时提示错误“无法打开备份设备“
[Microsoft][ODBC SQL Server Driver][SQL Server]无法打开备份设备 'C:\Users\dida\Desktop\EDI\EDI_TC\TA\App_Data\EDI(2008316222724).bak'。设备出现错误或设备脱机。详细信息请参阅 SQL Server 错误日志。
[Microsoft][ODBC SQL Server Driver][SQL Server]BACKUP DATABASE 操作异常终止。 

备份按钮的代码是这样的:
DBBackup dbb = new DBBackup();
dbb.DbBackup(MapPath("App_Data/"));


但是奇怪的是如果我不用MapPath获取路径,而直接手动输入路径就不会出现这个问题了
就像这样:
DBBackup dbb = new DBBackup();
dbb.DbBackup(@"C:\Users\dida\Desktop\EDI\EDI_TC\TA\App_Data\");

请教哪位大哥帮忙解答下!

备份代码如下:
  public bool DbBackup(string dbpath)
  {
  SQLDMO.Backup oBackup = new SQLDMO.BackupClass();
  SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
  try
  {
  oSQLServer.LoginSecure = false;
  oSQLServer.Connect(".", "sa", "sa");
  oBackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
  oBackup.Database = "EDI";
  //oBackup.Files = path;

  oBackup.Files = dbpath + "EDI(" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + @").bak";
  oBackup.BackupSetName = "EDI";
  oBackup.BackupSetDescription = "数据库备份";
  oBackup.Initialize = true;
  oBackup.SQLBackup(oSQLServer);

  this.AddRecord(EDITCEnum.Event.TA_Backup);

  return true;
  }
  catch(Exception ex)
  {
  throw ex;
  return false;
   
  }
  finally
  {
  oSQLServer.DisConnect();
  }
  }




------解决方案--------------------
用消息弹一下,看看是不是合法的路径
------解决方案--------------------
'C:\Users\dida\Desktop\EDI\EDI_TC\TA\App_Data\

存在这个路径吗?