Hope that those interested in web programming remember I have posted several threads regarding FCGI's rasing exceptions under IIS. Now there seems to be a possibility that this is caused by TDataModule or TWebmodule. Now I have made a fcgi application not using webmodule nor datamodule. Following is the codes.
unit ufcgi2;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, httpdefs, fpHTTP, fpWeb, httproute,
IBConnection, SQLDB;
var
IBConnection1: TIBConnection;
SQLQuery1: TSQLQuery;
SQLTransaction1: TSQLTransaction;
function TestContent: string;
procedure Hello (ARequest:TRequest; AResponse: TResponse);
implementation
uses DB;
var
cnt : integer = 0;
function TestContent: string;
var
Field: TField;
begin
with SQLQuery1 do begin
SQL.text := 'Select * from TEST';
Transaction.Active := True;
Open;
Result := '<table>';
First;
while not eof do begin
Result += '<tr>';
for Field in Fields do begin
Result += Format('<td>%s</td>', [Field.AsString]) ;
end;
Result += '</tr>';
Next;
end;
Result += '</table>';
(Transaction as TSQLTransaction).Rollback;
end;
end;
procedure Hello(ARequest: TRequest; AResponse: TResponse);
begin
cnt += 1;
AResponse.Content := 'Count: ' + IntToStr(cnt) + '<br>';
AResponse.Content := AResponse.Content + TestContent;
end;
initialization
ibconnection1 := TIBConnection.Create(nil);
with ibconnection1 do begin
DatabaseName:= 'd:\DBS\aq03.fdb';
Username := 'sysdba';
Password := 'masterkey';
Connected := True;
end;
sqltransaction1 := TSQLTransaction.Create(nil);
SQLTransaction1.DataBase := ibconnection1;
sqlquery1 := TSQLQuery.Create(nil);
sqlquery1.DataBase := ibconnection1;
HTTPRouter.RegisterRoute('*', @Hello);
finalization
ibconnection1.connected := False;
SQLQuery1.Free;
SQLTransaction1.Free;
ibconnection1.Free;
end.
Originally DB-related components were in a separate DataModule. With TDataModule, it causes errors after about 15~20 requests (by pressing F5).
But with the new approach listed above, I cannot cause the error how fast I press F5
Hope the developers may give some insights if possible.