You are not logged in.
Pages: 1
Hi Ab,
I have a server which I initialize as follows below. In my model I have a SQLRecord class which is TMessart. So, I start my server and do some REST requests from a client.
Q1: My REST requests works fine and I get data, but each time I send a http request to the server a new database connection is opened which is not closed after the request. Do you any idea how I can handle this?
Q2: In the code below if when ServerHTTP.Free is called an access violation occurs. If I debug into the method, the error is raised in THttpApiServer.Destroy the code check if fServerSessionID<>0 then begin
Is it a bug, or am I doing something wrong?
// INITIALIZE THE SERVER
DatabaseConnectionProperties := TSQLDBConnectionProperties.Create;
Model := CreateModel;
VirtualTableExternalRegister(Model, TMessart, DatabaseConnectionProperties, 'testdb.messart');
ServerDB := TSQLRestServerDB.Create(Model, ChangeFileExt(ExeVersion.ProgramFileName, '.db3'), False);
ServerDB.CreateMissingTables;
ServerHTTP := TSQLHttpServer.Create('7979', [ServerDB], '+', useHttpApiRegisteringURI);
ServerHTTP.AccessControlAllowOrigin := '*'; // allow cross-site AJAX queries
// DO SOME REST requests
http://localhost:7979/root/messart/1
http://localhost:7979/root/messart/2
http://localhost:7979/root/messart/3
...
... and so on
// SHUTDOWN THE SERVER
DatabaseConnectionProperties.Free;
Model.Free;
ServerDB.Free;
ServerHTTP.Free;
Offline
Q1. There is a connection per thread.
Once each thread of the thread pool has its connection, there won't be any more connection.
You may use a single thread for all ORM process - see http://synopse.info/files/html/Synopse% … #TITLE_195
Q2. You should free the instances in the REVERSE order of the initialization, not the same order, of course!
// SHUTDOWN THE SERVER
ServerHTTP.Free;
ServerDB.Free;
Model.Free;
DatabaseConnectionProperties.Free;
Offline
Great! It works! Thank you very much for your fast answer!
Offline
Pages: 1