数据库恢复后程序不能用,说连接失败或者表无效!
数据库还原后程序不能用,说连接失败或者表无效!
还原按钮的具体程序是这样的,希望大家给我解决一下,小弟十分感谢!
procedure TShujuku.SpeedButton2Click(Sender: TObject);
begin
Opendialog1.Title:='选择文件。';
if OPendialog1.Execute then
Edit2.Text:=opendialog1.FileName;
If Trim(opendialog1.FileName)<>'' then
begin
try
With Data.ADOQuery1 do
begin
Data.ADOQuery1.Close;
Data.ADOQuery1.SQL.Clear;
Data.ADOQuery1.SQL.Add('use master restore headeronly from disk='''+edit2.text+'''');
Data.ADOQuery1.Open;
end;
Data.ADOQuery1.Last;
Cou:=trim(Data.ADOQuery1.Fields.Fields[5].AsString);
While not Data.ADOQuery1.bof do
begin
Data.ADOQuery1.Prior;
end;
except
Application.MessageBox('错误!','提示',mb_ok);
end;
end;
if Edit2.Text = '' then
begin
Application.MessageBox('您已经取消数据库恢复!','提示',mb_ok);
exit;
end;
with Data.ADOConnection1 do
begin
try
ADOCommand1.CommandText:='use master';
ADOCommand1.Execute;
ADOCommand1.CommandText:=' alter database ZLManager set offline with rollback immediate';
ADOCommand1.Execute;
ADOCommand1.CommandText:='restore database ZLManager from disk= '''+edit2.Text+''' with recovery ';
ADOCommand1.Execute;
ADOCommand1.CommandText:=' alter database ZLManager set online with rollback immediate';
ADOCommand1.Execute;
Application.MessageBox('数据库恢复成功!','提示',mb_ok);
except
on e:exception do
begin
showmessage('数据库恢复失败,请重新恢复!'+e.Message);
end;
end;
end;
end;