【问题标题】:Datasnap Getting 10054 - Socket Error #10054 Connection reset by peer. in TDBXCommand.PrepareDatasnap 获取 10054 - 套接字错误 #10054 连接被对等方重置。在 TDBXCommand.Prepare 中
【发布时间】:2019-08-23 09:17:20
【问题描述】:

我有一个稳定的 Delphi 10.2.3 TCP/IP Datasnap 服务器和客户端,在 99.9% 的时间里都能正常工作。有时,用户会收到“10054 Connection reset by peer”错误。我使用Eurekalog,调用堆栈报告显示错误发生在生成的ClientClassesUnit 中的DBXCommand.Prepare 语句中:

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)

问题不在于连接到服务器失败,而在于连接没有“保持正常”,甚至没有几毫秒。

感谢任何cmets。

【问题讨论】:

    标签: delphi tcp datasnap


    【解决方案1】:

    虽然我并不想这样做,但我最终还是这样做了:

    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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-02
      • 2016-12-07
      • 2011-02-04
      • 1970-01-01
      相关资源
      最近更新 更多