我用asp.net写SQL server2000的数据库备份,写了一个方法
/// <summary>
    /// 数据库备份
    /// </summary>
    /// <param name="server">服务器地址</param>
    /// <param name="ad">sql账户</param>
    /// <param name="pw">sql密码</param>
    /// <param name="db">要备份的数据库名称</param>
    /// <param name="bkpath">备份路径</param>
    /// <param name="bkname">备份文件名</param>
    /// <param name="des">描述</param>
    public void DbBackup(string server, string ad, string pw, string db,
        string bkpath, string bkname, string des)
    {
        SQLDMO.Backup oBackup = new SQLDMO.BackupClass();
        SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
        try
        {
            oSQLServer.LoginSecure = false;
            oSQLServer.Connect(server, ad, pw);
            oBackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
            oBackup.Database = db;
            oBackup.Files = @"D:\Downloads";
            oBackup.BackupSetName = bkname;
            oBackup.BackupSetDescription = des;
            oBackup.Initialize = true;
            oBackup.SQLBackup(oSQLServer);
        }
        catch (Exception ex)
        {            throw ex;
        }
        finally
        {
            oSQLServer.DisConnect();
        }    }
然后调用这个方法进行备份,总是报出错误备份失败:[Microsoft][ODBC SQL Server Driver][SQL Server]无法打开备份设备 'D:\Downloads'。设备出现错误或设备脱机。详细信息请参阅 SQL Server 错误日志。 [Microsoft][ODBC SQL Server Driver][SQL Server]BACKUP DATABASE 操作异常终止。郁闷死了,请各位帮帮忙吧!

解决方案 »

  1.   

    'D:\Downloads'文件夹的权限我设置了一个Everyone具有完全权限,还需要设置别的吗?
      

  2.   

    'D:\Downloads'文件夹的权限我设置了一个Everyone具有完全权限,还需要设置别的吗?
      

  3.   

    检查下路径是否正确
    权限应该没问题了,你都设置过了
    看下硬盘格式,好象只能用于FAT格式
      

  4.   

    'D:\Downloads'路径是有的
    我D盘的格式就是FAT32的,系统是Windows XP3.
      

  5.   

    'D:\Downloads'路径是有的
    我D盘的格式就是FAT32的,系统是Windows XP3.
      

  6.   

    用存储过程
    CREATE proc dbo.Data_Backup  @dbname sysname='',@bkpath nvarchar(260)='',@bkfname nvarchar(260)='',@bktype nvarchar(10)='DB',@appendfile bit=1 
    as declare @sql varchar(8000)  if isnull(@dbname,'')='' set @dbname=db_name()  if isnull(@bkfname,'')='' 
    set @bkfname='\DBNAME\_\DATE\_\TIME\.BAK'  set @bkfname=replace(replace(replace(@bkfname,'\DBNAME\',@dbname),'\DATE\',convert(varchar,getdate(),112)),'\TIME\',replace(convert(varchar,getdate(),108),':','')) 
    update Tb_Page set FNAME=@bkfname
    set @sql='backup '+case @bktype when 'LOG' then 'log ' else 'database ' end +@dbname +' to disk='''+@bkpath+@bkfname +''' with '+case @bktype when 'DF' then 'DIFFERENTIAL,' else '' end+case @appendfile when 1 then 'NOINIT' else 'INIT' end 
    exec(@sql)
    GO
      

  7.   

    declare @spid varchar(20) declare #spid cursor for 
    select spid=cast(spid as varchar(20)) 
    from master..sysprocesses where dbid=db_id(@dbname) 
    open #spid fetch next from #spid 
    into @spid while @@fetch_status=0  
    begin  exec('kill '+@spid) fetch next from #spid into @spid End close #spid deallocate #spid  
      

  8.   

                oBackup.Files = @"D:\Downloads";
      这个是不是要连文件名一起设置
      

  9.   

    这个可以.在SQL SERVER 2000下通过
    create proc killspid (@dbname varchar(20))
    as
    begin
    declare @sql nvarchar(500)
    declare @spid int
    set @sql='declare getspid cursor for 
    select spid from sysprocesses where dbid=db_id('''+@dbname+''')'
    exec (@sql)
    open getspid
    fetch next from getspid into @spid
    while @@fetch_status<>-1
    begin
    exec('kill '+@spid)
    fetch next from getspid into @spid
    end
    close getspid
    deallocate getspid
    endGO
      

  10.   

    参考:
    http://blog.csdn.net/insus/archive/2008/03/30/2229854.aspx