var hfsjk: TADOQuery;
bfmc:string;
begin
if self.OpenDialog1.Execute then
begin
mydata.ADOConnection1.Close; //ADOConnection1,连在 dslfwxt 这个上的
mydata.ADOConnection1.Connected:=false;
bfmc:=self.OpenDialog1.FileName;
hfsjk:= TADOQuery.Create(self);
hfsjk.Connection:=mydata.ADOConnection2;
mydata.ADOConnection1.Connected:=false;
hfsjk.SQL.Clear;
hfsjk.SQL.Add('restore database dslfwxt from disk='+#39+bfmc+#39);
if hfsjk.ExecSQL<>0 then
begin
mydata.ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Password=12345;Persist Security Info=True;User ID=sa;Initial Catalog=dslfwxt;Data Source=TYP';
mydata.ADOConnection1.Connected:=true;
end;
end;
我把 dslfwxt 删掉就可以,现在我要在上面覆盖,就不不可以阿,提示,正在访问,不能获得排他访问权
bfmc:string;
begin
if self.OpenDialog1.Execute then
begin
mydata.ADOConnection1.Close; //ADOConnection1,连在 dslfwxt 这个上的
mydata.ADOConnection1.Connected:=false;
bfmc:=self.OpenDialog1.FileName;
hfsjk:= TADOQuery.Create(self);
hfsjk.Connection:=mydata.ADOConnection2;
mydata.ADOConnection1.Connected:=false;
hfsjk.SQL.Clear;
hfsjk.SQL.Add('restore database dslfwxt from disk='+#39+bfmc+#39);
if hfsjk.ExecSQL<>0 then
begin
mydata.ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Password=12345;Persist Security Info=True;User ID=sa;Initial Catalog=dslfwxt;Data Source=TYP';
mydata.ADOConnection1.Connected:=true;
end;
end;
我把 dslfwxt 删掉就可以,现在我要在上面覆盖,就不不可以阿,提示,正在访问,不能获得排他访问权
hfsjk.SQL.Add('Restore')
adoconnection2 连 master
数据还原时,千万不能以SA用户登录
因为数据还原时,会首先杀掉所有的进程
建议:
程序以类似SA的用户连接数据源
根据连接动态生成一个以SA登记的新连接
在新连接中还原数据库(原因见上)