我有一个用delphi编写的简单Web服务器,它可以从数据库中获取数据并在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
以某种方式失去了连接,无法再次获得连接。有帮助吗?