Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separate dbx connection to a thread

I made a small app that connects to a mysql db using dbx. It works ok with my local mysql server, but it's supposed to work with a remote server.

Connecting to the remote server takes a few seconds, which freezes the app.

So my question is, how can I put the connection code in a different thread?

I'll have to pass that connection to the main thread somehow, so that the dbgrid I have on the main form works.

I read that db stuff working in a different thread should have their own connections. So I'm not sure how to do what I want.

Any ideas? Anything to read about working with remote servers?

Thanks.

Edit: The components I'm using on the form are: TSQLConnection -> TSimpleDataSet > TDataSource > TDBGrid.

like image 860
Mario Avatar asked Nov 14 '22 13:11

Mario


1 Answers

You only need a connection per thread if your threads are going to do simultaneous database access. Basically what you want, is for a thread to connect, and come back to you when the connection has been established. You can do this in a thread, and when the thread is ready (i.e. connection established), it can send a message back to the main thread to let it know that the dbx connection is now available. See this tutorial for ideas on how to set up the thread, and communicate between the thread and the main VCL thread. Threading Tutorial

like image 102
Steve Avatar answered Dec 10 '22 03:12

Steve