gpt4 book ai didi

delphi - 从 Delphi 执行脚本时出现错误 "invalid transaction handle (expecting explicit transaction start)"

转载 作者:行者123 更新时间:2023-12-03 15:57:43 26 4
gpt4 key购买 nike

我正在使用 Delphi 10 开发更新应用程序。我运行的是 Windows 7 64x、FireBird 2.5.1.26351 32x。

执行顺序:

  • 检查当前版本(从 Firebird 数据库中选择语句)
  • 下载更新(通过 FTP)
  • 应用它(.exe 文件,并执行.sql)

当我尝试执行 .SQL 文件时,弹出错误代码 -901。我知道 W7 64x 和 FDB 32x 存在不兼容问题,但是,我可以做一切:备份和恢复(gb​​ak)、DB 命令(全部)。我尝试使用 FDB 64x,但它不起作用。

代码:

//Components
FDWaitCursor: TFDGUIxWaitCursor;
FDDriverLink: TFDPhysFBDriverLink;
FDConnection:TFDConnection;
FDScript: TFDScript;

function TTHR_Script.CreateComponents:boolean;
begin
try
FDDriverLink := TFDPhysFBDriverLink.Create(FDDriverLink);
FDWaitCursor := TFDGUIxWaitCursor.Create(FDWaitCursor);

FDConnection := TFDConnection.Create(FDConnection);
with FDConnection do
begin
DriverName := 'FB';
Params.UserName := THRBanco.BDUser;
Params.Password := THRBanco.BDPass;
Params.Database := THRBanco.DIROrigem;
end;

FDScript := TFDScript.Create(FDScript);
with FDScript do
begin
Connection := FDConnection;
OnConsolePut := FDScript_ConsolePut;
end;
Result := true;
except on E:Exception do
begin
Result := false;
end;
end;
end;

procedure TTHR_Script.ExecLogs;
var
F : integer;
SR : TSearchRec;
begin
F := FindFirst(ExtractFilePath(Application.ExeName)+'\manager\update\logs\*.sql',faArchive,SR);
FDConnection.Open;

while F = 0 do
begin
with FDScript do
begin
SQLScripts.Clear;
SQLScriptFileName := ExtractFilePath(Application.ExeName)+'\manager\update\logs\'+SR.Name;
ValidateAll;
ExecuteAll;
end;
Application.ProcessMessages;
F := FindNext(SR);
end;
FDConnection.Close;
end;

安装 Firebird 2.5.6 后,仍然出现相同的 -901 错误。错误日志:

update empresa set emp_verbanco='2016.55'; 
[13_09_2016 | 14:29]: Ok [00:00:00.047].
[13_09_2016 | 14:29]: update empresa set emp_versis='2016.55';
[13_09_2016 | 14:29]: Ok [00:00:00.016].
[13_09_2016 | 14:29]: commit work;
[13_09_2016 | 14:29]: ERROR: Dynamic SQL Error SQL error code = -901 invalid transaction handle (expecting explicit transaction start)

最佳答案

该错误表明您遇到了“COMMIT WORK;”之类的情况在你的sql脚本中。

根据 FireDAC 文档:

Resolving Incompatibilities

Firebird ISQL works in non-autocommit mode. By default, the autocommit mode for TFDScript/TFDConnection is turned on. For better compatibility, set FDConnection.TxOptions.AutoCommit to False before the script execution. Or execute the SET AUTOCOMMIT OFF script command.

http://docwiki.embarcadero.com/RADStudio/Berlin/en/Executing_SQL_Scripts_(FireDAC)

关于delphi - 从 Delphi 执行脚本时出现错误 "invalid transaction handle (expecting explicit transaction start)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39471426/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com