调用函数 共调用5次 可是执行到第二次时。。程序会出错!
heidunlogDBBackup('data1'+vsNo,'data1');//程序执行第一次的时候不会出错
heidunlogDBBackup('data2'+vsNo,'data2');//程序执行第二次调用的时候出现错误
//Commands out of sync; you can't run this command now
heidunlogDBBackup('data3'+vsNo,'data3');
heidunlogDBBackup('data4'+vsNo,'data4');
heidunlogDBBackup('data5'+vsNo,'data5');
//被调函数
procedure heidunlogDBBackup(backupDBName,DangqianDBName: string);
var
tmp_query:Tsqlquery;
begin
tmp_query:= Tsqlquery.Create(nil);
tmp_query.SQLConnection:=HeidunSqlQuery.SQLConnection;
//HeidunSqlQuery.Destroy;
tmp_query.Close;
tmp_query.sql.text := format('alter table %s rename as %s ',[DangqianDBName,backupDBName]); //这个是更改数据表名字!
tmp_query.ExecSQL ;//程序执行第二次调用。运行到这里时。出现如下错误
//Commands out of sync; you can't run this command now
tmp_query.Close;
tmp_query.sql.text :=format(CreateHDLogDBSqlstr,[DangqianDBName]);//这个执行的是重新创
tmp_query.ExecSQL; //建一个DangqianDBName的数据表
tmp_query.Destroy;
tmp_query:=nil;
tmp_query.Free;
//如果 DBBackUpIP 不等于0,则需要网络备份
end;
请问大家如何解决。。请帮帮忙呀
heidunlogDBBackup('data1'+vsNo,'data1');//程序执行第一次的时候不会出错
heidunlogDBBackup('data2'+vsNo,'data2');//程序执行第二次调用的时候出现错误
//Commands out of sync; you can't run this command now
heidunlogDBBackup('data3'+vsNo,'data3');
heidunlogDBBackup('data4'+vsNo,'data4');
heidunlogDBBackup('data5'+vsNo,'data5');
//被调函数
procedure heidunlogDBBackup(backupDBName,DangqianDBName: string);
var
tmp_query:Tsqlquery;
begin
tmp_query:= Tsqlquery.Create(nil);
tmp_query.SQLConnection:=HeidunSqlQuery.SQLConnection;
//HeidunSqlQuery.Destroy;
tmp_query.Close;
tmp_query.sql.text := format('alter table %s rename as %s ',[DangqianDBName,backupDBName]); //这个是更改数据表名字!
tmp_query.ExecSQL ;//程序执行第二次调用。运行到这里时。出现如下错误
//Commands out of sync; you can't run this command now
tmp_query.Close;
tmp_query.sql.text :=format(CreateHDLogDBSqlstr,[DangqianDBName]);//这个执行的是重新创
tmp_query.ExecSQL; //建一个DangqianDBName的数据表
tmp_query.Destroy;
tmp_query:=nil;
tmp_query.Free;
//如果 DBBackUpIP 不等于0,则需要网络备份
end;
请问大家如何解决。。请帮帮忙呀
tmp_query:=nil;
tmp_query.Free;
这段代码错误。
tmp_query.Free;
一句即可。 tmp_query.sql.text := format('alter table %s rename as %s ',[DangqianDBName,backupDBName]); 当第二次调用时,backupDBName 是否已经存在了?
heidunlogDBBackup('data1'+vsNo,'data1');//程序执行第一次的时候不会出错
heidunlogDBBackup('data2'+vsNo,'data2');
这里第二次调用时。。backupDBName 会等于‘data2’+vsno,vsno是当前的日期字符串。。我已经把它转换成字符!
我把
heidunlogDBBackup('data1'+vsNo,'data1');//程序执行第一次的时候不会出错
heidunlogDBBackup('data2'+vsNo,'data2');程序置换了一下,程序还是在第二次调用的
并执行到
tmp_query.ExecSQL ;//程序执行第二次调用。运行到这里时。出现如下错误
//Commands out of sync; you can't run this command now
出现错误
procedure heidunlogDBBackup(backupDBName,DangqianDBName: string);
begin
HeidunSqlQuery.SQLConnection.Execute(
format('alter table %s rename as %s ',[DangqianDBName,backupDBName])+
format(CreateHDLogDBSqlstr,[DangqianDBName]));
end;
如果再不行,把这两条语句分别执行,再不行,使用Command组件执行
能把句子写完整点吗?要不运行有错误!