用BatchMove的代码如下:
Table1.Close;
Table2.Close;
//********************更新sourceclip表***************************
table1.DatabaseName :=hbz;
table1.tableName :='sourceclip';
table1.Open;
table2.DatabaseName :=hbb;
table2.tableName :=table1.TableName ;
if not table2.Exists then
begin
batchmove:=tbatchmove.Create(application);
table2.BatchMove(table1,batcopy);
batchmove.Free;
table2.AddIndex('newsourceclipindex','title',[ixunique]);
end
else begin
batchmove:=tbatchmove.Create(application);
table2.BatchMove(table1,batappendupdate);
batchmove.Free;
end;
table1.Close;
table2.Close;
showmessage('备数据库更新完成!');
//********************end****************************************还原restore的代码如下:
filename:=pathedit.Text+'\'+FileListBox1.Items.Strings[filelistbox1.itemindex];
Query1.Close;
Query1.DatabaseName:=bandr;
Query1.SQL.Clear();
//Query1.SQL.Add('USE master');
Query1.SQL.Add('restore DATABASE '+dbname+' from disk=:dbnamepath');
Query1.ParamByName('dbnamepath').AsString:=filename;
Query1.ExecSQL();
showmessage('完成 '+dbname+' 数据库还原!');如果单独进行还原操作可以完成,可是先更新数据后再restore就不行,提示数据库正在使用,可我明明已经table close了啊,请问该怎么解决啊,急,在线等!
Table1.Close;
Table2.Close;
//********************更新sourceclip表***************************
table1.DatabaseName :=hbz;
table1.tableName :='sourceclip';
table1.Open;
table2.DatabaseName :=hbb;
table2.tableName :=table1.TableName ;
if not table2.Exists then
begin
batchmove:=tbatchmove.Create(application);
table2.BatchMove(table1,batcopy);
batchmove.Free;
table2.AddIndex('newsourceclipindex','title',[ixunique]);
end
else begin
batchmove:=tbatchmove.Create(application);
table2.BatchMove(table1,batappendupdate);
batchmove.Free;
end;
table1.Close;
table2.Close;
showmessage('备数据库更新完成!');
//********************end****************************************还原restore的代码如下:
filename:=pathedit.Text+'\'+FileListBox1.Items.Strings[filelistbox1.itemindex];
Query1.Close;
Query1.DatabaseName:=bandr;
Query1.SQL.Clear();
//Query1.SQL.Add('USE master');
Query1.SQL.Add('restore DATABASE '+dbname+' from disk=:dbnamepath');
Query1.ParamByName('dbnamepath').AsString:=filename;
Query1.ExecSQL();
showmessage('完成 '+dbname+' 数据库还原!');如果单独进行还原操作可以完成,可是先更新数据后再restore就不行,提示数据库正在使用,可我明明已经table close了啊,请问该怎么解决啊,急,在线等!
解决方案 »
- 晕了,要问了,我程序里调用一个CMD模式下的程序叫DFC.EXE,他有一个返回值,怎么在我的程序里接收这个返回值呢?
- 如何在COMBOX出现的下拉列表的每项上移动时加入事件代码?并且能知道目前焦点在下拉列表的哪一项上?
- 关于Intraweb中WebApplication.ShowMessage()的问题,知道的请进来看看!
- 开贴补1000分,请 ly_liuyang(Liu Yang) 进来接分(10)
- 我根据SGIP(联通短信协议)编写的短信接口程序,大家观摩多提意见!!
- 一个问题
- 请教一个多线程编程问题
- 怎么用代码动态连接DB数据库?
- 提个错误的问题,哈。。当然是出错才麻烦各位。
- 关于我和我的文章的一些想法
- SQLSERVER 如何进行双机备份请教各位大侠!
- 如何写一个数据备份软件
参数:databasename数据库名,filename数据库备份文件名
////////////////////////////////////////////////////////
function sqlrestore(databasename,filename:string):boolean;
begin
if (databasename<>'') and (filename<>'') then
begin
try
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.CommandTimeout:=120;
adoquery1.SQL.Add('use master');
adoquery1.SQL.Add('alter database '+databasename+' set offline WITH ROLLBACK IMMEDIATE');
adoquery1.SQL.Add('restore database '+databasename+' from disk='''+filename+''''+' with REPLACE ');
adoquery1.SQL.Add('alter database '+databasename+' set online with rollback immediate');
adoquery1.ExecSQL;
result:=true;
except
result:=false;
exit;
end;
end;
end;////////////////////////////////////////////////////////
功能:SQL数据库备份
参数:databasename数据库名,savepath数据库备份文件名
////////////////////////////////////////////////////////
function TForm7.sqlback(databasename,savepath:string):boolean;
begin
if (databasename<>'')and (savepath<>'') then
begin
try
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('backup database '+databasename+ ' to disk='''+savepath+'''');
adoquery1.ExecSQL;
result:=true;
except
result:=false;
exit;
end;
end;
end;