delphi - Datasnap 获取 10054 - 套接字错误 #10054 连接被对等方重置。在 TDBXCommand.Prepare 中
问题描述
我有一个稳定的 Delphi 10.2.3 TCP/IP Datasnap 服务器和客户端,可以在 99.9% 的时间里完美运行。有时,用户会收到“10054 Connection reset by peer”错误。我使用 Eurekalog,调用堆栈报告显示错误发生在DBXCommand.Prepare
生成的语句中ClientClassesUnit
:
function TServerMethods3Client.UpdateTask(ID: Integer): Boolean;
begin
if FUpdateTaskCommand = nil then
begin
FUpdateTaskCommand := FDBXConnection.CreateCommand;
FUpdateTaskCommand.CommandType := TDBXCommandTypes.DSServerMethod;
FUpdateTaskCommand.Text := 'TServerMethods3.UpdateTask';
FUpdateTaskCommand.Prepare; // --> exception is raised here
end;
FUpdateTaskCommand.Parameters[0].Value.SetInt32(ID);
当然,与 Datasnap 服务器的连接是在 calll to server 方法之前实现的,使用通常的方法:
SQLConnection1.Connected := True
Server := TServerMethods3Client.Create(SQLConnection1.DBXConnection);
try
Result := Server.UpdateTask(CDSTask.FieldByName('ID').AsInteger)
问题不在于连接到服务器失败,而是连接没有“保持正常”,甚至几毫秒都没有。
任何意见表示赞赏。
解决方案
尽管我真的不想这样做,但我最终这样做了:
function ClientModule1.UpdateTask: Boolean;
var
i: integer
begin
Result := False;
i := 0;
while (i < 3) and (not Result) do
begin
if ServerConnect then
begin
Server := TServerMethods3Client.Create(SQLConnection1.DBXConnection);
try
try
Result := Server.UpdateTask(CDSTask.FieldByName('ID').AsInteger);
except
on e: exception do
begin
inc(i)
if i = 3 then
MessageDlg(e.Message, mtError, [mbOk], 0);
Sleep(1000);
end
end
finally
Server.Free;
SQLConnection1.Connected := False;
end;
end;
end;
end;
function ClientModule1.ServerConnect: Boolean;
var
i: Integer;
begin
if SQLConnection1.Connected then
SQLConnection1.Close;
i := 0;
while (not SQLConnection1.Connected) and (i < 3) do
begin
try
SQLConnection1.Open;
except
on e: exception do
begin
inc(i)
if i = 3 then
MessageDlg(e.Message, mtError, [mbOk], 0);
sleep(1000);
end;
end;
end;
end;
推荐阅读
- sql - java.sql.SQLException:ORA-06550:第 1 行,第 4 列:PLS-00103:遇到符号“文件结尾”
- python - 使用 Python 和 Selenium 抓取特定酒店所有页面的 Tripadvisor 评论
- generics - 如何在 Rust 中定义具有不同 const 参数的结构族?
- javascript - 在 Javascript 中使用带有函数的 for 循环
- python - 马尔可夫链:找到从 A 点到 B 点的最可能路径
- arcgis-runtime - ArcGIS Runtime:如何确定两个 3D 几何之间的关系
- pytorch - 带有注意力的神经机器翻译中的嵌入层
- spring-cloud-dataflow - Spring Cloud Data Flow- 任务执行失败并出现错误 ErrImgPull
- python - 有两个 jupyter notebook 选项,一个有效但一个有“错误启动内核”
- java - 使用Apache POI保留excel单元格值的单引号前缀