procedure TForm9.SpeedButton3Click(Sender: TObject);
begin
if edit1.Text='' then
showmessage('请选择备份到哪个路径!')
else
begin
screen.Cursor:=crhourglass;
label1.Visible:=true;
label1.Update;
ADOCommand1.CommandText:='';
ADOCommand1.CommandText:='backup database ylw to disk =:path with init';
ADOCommand1.Parameters.ParamByName('path').Value:=trim(edit1.Text);
ADOCommand1.Execute;
label1.Visible:=false;
label1.Update;
screen.Cursor:=crdefault;
application.messagebox('备份完成','提示',MB_OK);
end;
end;procedure TForm9.SpeedButton4Click(Sender: TObject);
begin
close;
end;procedure TForm9.SpeedButton7Click(Sender: TObject);
begin
if edit4.Text='' then
showmessage('请选择要的还原数据库!')
else
begin
dm.ADOConnection1.Close ;
screen.Cursor:=crhourglass;
label4.Visible:=true;
label4.Update;
ADOCommand1.CommandText:='';
ADOCommand1.CommandText:='restore database ylw from disk=:path with replace';
ADOCommand1.Parameters.ParamByName('path').Value:=trim(edit4.Text);
ADOCommand1.Execute;
label4.Visible:=false;
label4.Update;
application.messagebox('还原完成','提示',MB_OK);
screen.Cursor:=crdefault;
end;
end;我这上面是数据库备份与还原代码,可是还原时会提示:数据库正在使用中,应怎么改呢?

解决方案 »

  1.   


    procedure TForm9.SpeedButton7Click(Sender: TObject); 
    begin 
    if edit4.Text='' then 
    showmessage('请选择要的还原数据库!') 
    else 
    begin 
    dm.ADOConnection1.Close ; 
    screen.Cursor:=crhourglass; 
    label4.Visible:=true; 
    label4.Update; 
    ADOCommand1.CommandText:=''; 
    ADOCommand1.CommandText:='use master restore database ylw from disk=:path with replace'; //还原语句前面加上 use master 
    ADOCommand1.Parameters.ParamByName('path').Value:=trim(edit4.Text); 
    ADOCommand1.Execute; 
    label4.Visible:=false; 
    label4.Update; 
    application.messagebox('还原完成','提示',MB_OK); 
    screen.Cursor:=crdefault; 
    end; 
    end;