我用如下代码:
try
OpenDialog1.Execute;
ADOCommand1.Connection:=DataModule1.ADOConnection2;
ADOCommand1.CommandText:='ALTER DATABASE cemeterydb_srv SET OFFLINE WITH ROLLBACK IMMEDIATE';
ADOCommand1.Execute; ADOCommand1.CommandText:='RESTORE DATABASE cemeterydb_srv FROM DISK= '''+Opendialog1.FileName+'''';
ADOCommand1.Execute;
self.Caption :='数据恢复中,请稍等......';
showmessage('数据恢复成功');
self.Caption :='恢复数据库';
finally
ADOCommand1.CommandText:='ALTER DATABASE cemeterydb_srv SET ONLINE WITH ROLLBACK IMMEDIATE';
ADOCommand1.Execute;
DataModule1.ADOConnection2.Connected:=False;
end;但问题是:
老提示“超时已过期”。
我的数据库文件有点大。。大概在20M大家给我点办法吧。
try
OpenDialog1.Execute;
ADOCommand1.Connection:=DataModule1.ADOConnection2;
ADOCommand1.CommandText:='ALTER DATABASE cemeterydb_srv SET OFFLINE WITH ROLLBACK IMMEDIATE';
ADOCommand1.Execute; ADOCommand1.CommandText:='RESTORE DATABASE cemeterydb_srv FROM DISK= '''+Opendialog1.FileName+'''';
ADOCommand1.Execute;
self.Caption :='数据恢复中,请稍等......';
showmessage('数据恢复成功');
self.Caption :='恢复数据库';
finally
ADOCommand1.CommandText:='ALTER DATABASE cemeterydb_srv SET ONLINE WITH ROLLBACK IMMEDIATE';
ADOCommand1.Execute;
DataModule1.ADOConnection2.Connected:=False;
end;但问题是:
老提示“超时已过期”。
我的数据库文件有点大。。大概在20M大家给我点办法吧。
var
Str: string;
begin
DataModule2.ADOConnection1.Connected := false;
ADOConn.Connected := False;
ADOConn.ConnectionString := 'Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=master;Data Source=SAILOR';
ADOConn.Open;
if edit1.Text <> '' then
begin
Str := 'restore database test from disk = '+ #39 + edit1.Text + #39 + ' with replace, '
+ 'move ' + #39 + 'test_data' + #39 + ' to ' + #39 + 'C:\Program Files\Microsoft SQL Server\MSSQL\data\test_Data.MDF' + #39
+ ',move ' + #39 + 'test_log' + #39 + ' to ' + #39 + 'C:\Program Files\Microsoft SQL Server\MSSQL\data\test_Log.LDF' + #39;
with Adoquery1 do
begin
close;
sql.Clear;
sql.Add('ALTER DATABASE test SET OFFLINE WITH ROLLBACK IMMEDIATE');
try
ExecSQL;
except end;
close;
sql.Clear;
sql.Text := Str;
try
execsql;
application.MessageBox('成功','asdf',mb_ok+ mb_iconinformation);
except
application.MessageBox('错误','asdf',mb_ok+ mb_iconstop);
end;
close;
sql.Clear;
sql.Add('ALTER DATABASE test SET ONLINE WITH ROLLBACK IMMEDIATE');
try
ExecSQL;
except end;
end;
end;
ADOConn.Connected := false;
DataModule2.ADOConnection1.Connected := True;
end;