我用的是
  adoquery1.Close;
  adoquery1.SQL.Clear;
  adoquery1.SQL.Add('restore database 数据库名 from disk='''+'D:\qiujing\bak\2003-09-05.mdf'+''' with replace');
  adoquery1.ExecSQL;
然后提示说:Project setup1.exe raised exception class EOLeException with message 'The file '数据库路径'cannot be overwritten.It is being used by database '数据库名'.Process stopped.Use Step or Run to continue.
哪位知道是怎么回事啊?

解决方案 »

  1.   

    數據庫正在使用﹐先kill使用他的進程
    use  master 
    go
    create  proc  killspid  (@dbname  varchar(20))  
    as  
    begin  
    declare  @sql  nvarchar(500),@temp varchar(1000)
    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  
      set @temp='kill  '+rtrim(@spid)
      exec(@temp)
    fetch  next  from  getspid  into  @spid  
    end  
    close  getspid  
    deallocate  getspid  
    end  use  master  
    exec  killspid  'dbname'
      

  2.   

    while  @@fetch_status  <  >-1  
    應是while  @@fetch_status =0