procedure Tfbackstore.BitBtn2Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
with data.backstorequery do
begin
try
data.connection.Connected:=false;
DisableControls;
Close;
SQL.Clear;
Parameters.Clear;
SQL.Add('RESTORE DATABASE projectmanage from disk = ''' + OpenDialog1.FileName + ''' WITH RESTART');
ExecSQL;
ShowMessage('恢复成功!');
data.connection.Connected:=true;
Close;
EnableControls;
except
ShowMessage('恢复失败!');
exit;
end;
end;
end;
end;
数据库正在使用,没有获得排它访问权!怎么解决,大家帮帮忙
很急,在线等
begin
if OpenDialog1.Execute then
begin
with data.backstorequery do
begin
try
data.connection.Connected:=false;
DisableControls;
Close;
SQL.Clear;
Parameters.Clear;
SQL.Add('RESTORE DATABASE projectmanage from disk = ''' + OpenDialog1.FileName + ''' WITH RESTART');
ExecSQL;
ShowMessage('恢复成功!');
data.connection.Connected:=true;
Close;
EnableControls;
except
ShowMessage('恢复失败!');
exit;
end;
end;
end;
end;
数据库正在使用,没有获得排它访问权!怎么解决,大家帮帮忙
很急,在线等
var conn: tadoconnection;
ado: tadocommand;
a: integer;
begin
if Application.MessageBox('数据库恢复功能只能在服务器上执行,请先确认计算机是要恢复的服务器,并且现在没有任何程序正在使用数据库,是否现在进行恢复?', '提示', mb_yesno + mb_iconquestion) = idno then
abort
else
begin
if RzOpenDialog1.Execute then
begin
conn := tadoconnection.Create(nil);
conn.LoginPrompt := false;
conn.Connected := false;
conn.ConnectionString := 'Provider=SQLOLEDB.1;User ID=' + datamodule1.user + ';Password=;Data Source=' + Datamodule1.server + '';
datamodule1.ADOConnection1.Connected := false;
conn.Connected := true;
ado := tadocommand.Create(nil);
ado.Connection := conn;
ado.CommandTimeout := 300;
ado.CommandText := 'use master Restore database Wlzls from disk=''' + RzOpenDialog1.FileName + '''';
try
ado.Execute;
except
Application.MessageBox('数据还原失败,请确认没有其它程序已经连接到数据库!', '提示', MB_OK + MB_ICONSTOP);
Exit;
end;
ado.Free;
Application.MessageBox('数据还原成功!', '提示', MB_OK);
end;
end;
end;