[英]Delphi webserver broke after multiple calls at the same time
我有一个用delphi编写的简单网络服务器,该服务器从数据库中获取数据并以JSON
检索。
有20个端点,我将发布其中一个:
procedure TWM.WMactGruposGetAction(Sender: TObject; Request: TWebRequest;
Response: TWebResponse; var Handled: Boolean);
var
...
begin
// Get query fields
...
// Configurar resposta
Response.ContentType := APPLICATION_JSON + '; ' + CHARSET_UTF8;
// Look for grupos
qryGrupos := TFDQuery.Create(nil);
with qryGrupos do
begin
Connection := dmDados.GetConnection(NomeDB); // Open the
Active := False;
SQL.Clear;
Open('SELECT * FROM ' + T_PESSOAS_GRUPO +
' WHERE ' + C_ID_LOTEAMENTO + ' = ' + IDLoteamento);
if qryGrupos.RecordCount > 0 then
JsonArray := TJSONArray.Create;
try
First;
while not Eof do
begin
JsonObject := TJSONObject.Create;
CapturarCamposGrupos(JsonObject, qryGrupos);
JsonArray.AddElement(JsonObject);
Next;
end;
finally
Response.Content := JsonArray.ToString;
CloseQuery(qryGrupos); // Close and nil the query
dmDados.CloseConnection(NomeDB); // Close the TFDConnection
JsonArray.DisposeOf;
end;
end;
end;
function TdmDados.GetConnection(DBName: string): TFDConnection;
begin
FDConnection.Open();
Result := FDConnection
end;
基本上,这将执行以下操作:
TFDConnection
TFDQuery
;TFDQuery
;TFDConnection
; 注意: TFDConnection
是在应用程序启动时的设计时创建的,因此每个API调用都使用相同的TFDConnection
;
问题是在我的flutter应用程序中,我同时调用了三个端点(它们几乎与这个grupos端点执行相同的操作)。 当我一次调用每个端点时,它可以正常工作,但是当我转到此页面时,可以同时调用三个端点。 网络服务器坏了。
错误消息有所不同,但它们类似于:
Lost connection to MySQL server
Access violation address at ...
Cannot connect to MySQL
然后,服务器再也无法为任何端点工作。
我觉得TFDConnection
某种程度上失去了连接,无法再次获得连接。 有什么帮助吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.