sql - Indy Server and AdoQuery are conflicting -
i have 2 programs 1 client other server client. client sends info server , reads response:
idtcpclient1.writeln(command); //command contains info server needs eg. name , surname progressbar1.stepit; sresult := idtcpclient1.readln();
the server reads line, manipulates , creates sql query.
adoquery1.close; adoquery1.sql.text := 'select * '+sgrade; adoquery1.open;
but opens connection database client gives error "connection closed gracefully"
i have tested server code without client simulating input , works fine.
i think indy , adoquery conflicting if why , how can prepare it
if not problem , how should prepare it?
ado uses apartment-threaded com objects have affinity thread creates them. cannot used across thread boundaries unless marshalled.
indy's tcp server multi-threaded. each client runs in own thread.
a thread must phone call coinitialize/ex()
found relationship com before can access com objects, , phone call couninitialize()
when done using com.
your server fails because raising uncaught exception disconnects client. because did not initialize com.
you need create ado objects on per-client basis, not utilize them main thread. in server's onconnect
event, phone call coinitialize/ex()
. in ondisconnect
event, phone call couninitialize()
. in onexecute
event, dynamically create , utilize new ado objects needed.
this mean each client need own database connection. if not want that, move ado logic dedicated thread clients can post requests when needed. remain away doing database work in main thread, not belong there.
sql delphi delphi-7 indy tadoquery
No comments:
Post a Comment