Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Share TADOConnection between usersessions?


This question is answered.


Permlink Replies: 6 - Last Post: Oct 20, 2014 8:36 AM Last Post By: Dan Barclay
Dan Barclay

Posts: 889
Registered: 11/9/03
Share TADOConnection between usersessions?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 4:03 PM
My existing (client app) users connect to database(s)... existing code uses TADODataset(s) connected by a TADOConnection to the server.

Do I still need to maintain TADOConnections for each user (usersession), or can I put a common TADOConnection in the app and only put TADODataset(s) in the usersession?

Is this done routinely? I'm wondering a bit about thread safety with multiple sessions hitting the common TADODataset.

Experience with this?

Thanks,
Dan
[edit] XE2 with IW 14....
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: Share TADOConnection between usersessions?
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 4:29 PM   in response to: Dan Barclay in response to: Dan Barclay
I think you can do that. It shouldn't be to difficult to test. All you would be sharing is the connection. The ADOTables would still handle individual cursors and states. You have to try it with two active sessions going. In particular, editing, deleting and posting.

Here is the text from the help file "TADOConnection encapsulates the ADO connection object. Use TADOConnection for connecting to ADO data stores. The connection provided by a single TADOConnection component can be shared by multiple ADO command and dataset components through their Connection properties".
Dan Barclay

Posts: 889
Registered: 11/9/03
Re: Share TADOConnection between usersessions?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 17, 2014 10:08 PM   in response to: Daniel Fields in response to: Daniel Fields
Daniel Fields wrote:
I think you can do that. It shouldn't be to difficult to test. All you would be sharing is the connection. The ADOTables would still handle individual cursors and states. You have to try it with two active sessions going. In particular, editing, deleting and posting.

Here is the text from the help file "TADOConnection encapsulates the ADO connection object. Use TADOConnection for connecting to ADO data stores. The connection provided by a single TADOConnection component can be shared by multiple ADO command and dataset components through their Connection properties".

Thanks for the response!

Yea, I'm doing that now in a desktop environment... but that's all in one thread. I put on one TADOConnection and only have to deal with one connection string and one connecting event. I stitch up a bunch of dataset components to it.

A little testing might "accidentally work" but fail with more rigorous load. Collisions may not happen until it's loaded up and I'm not sure I have the ability to load it up. Before I commit to that I'd like to know somebody has beat on it pretty hard.

Maybe I should be asking in a Database forum?? This may be a more generic Delphi or ADO question rather than IW?

I have been working under the assumption that the only "special condition" that IW brings to the table on this is that all the sessions are in different threads, which is also different from the ServerController. If that is not correct, maybe somebody can set me straight. I've only been prototyping so far and haven't got the Ultimate with source. Some of my answers may be in there.

More thoughts?

Dan
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: Share TADOConnection between usersessions?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 18, 2014 12:36 AM   in response to: Dan Barclay in response to: Dan Barclay
That is correct. Each session is a separate thread, and separate from the server controller. I would try putting the connection there because it already exists at the time each user session is created.

You could still set it as a property at design-time if you use the unit in the UserSession. You could have write code in the OnCreate for the UserSession that assigned the shared connection. You could refererence the connection as IWServerController.MyConnection.
Dan Barclay

Posts: 889
Registered: 11/9/03
Re: Share TADOConnection between usersessions?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 18, 2014 9:20 PM   in response to: Daniel Fields in response to: Daniel Fields
Daniel Fields wrote:
That is correct. Each session is a separate thread, and separate from the server controller. I would try putting the connection there because it already exists at the time each user session is created.

You could still set it as a property at design-time if you use the unit in the UserSession. You could have write code in the OnCreate for the UserSession that assigned the shared connection. You could refererence the connection as IWServerController.MyConnection.

Thanks. I've also posted over on database.ado to see if anybody can answer the question of whether the ADO components play well with multiple threads.

https://forums.embarcadero.com/thread.jspa?threadID=109435&tstart=0

Maybe somebody knows the answer to that. Nothing there so far. This can't be the first time this has come up. Too bad the history (previous messages) don't seem to be around any more.

Dan
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: Share TADOConnection between usersessions?
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2014 2:17 PM   in response to: Dan Barclay in response to: Dan Barclay
I found the answer. No! ADO is COM based technology that uses permanent, internal threads. You have to create one for each session, which means it goes into the UserSession. That makes sense because of ADO's age. There are plenty of newer and third-party options to access data.

Here is the source
http://stackoverflow.com/questions/1241844/is-delphis-tadoconnection-thread-safe
Dan Barclay

Posts: 889
Registered: 11/9/03
Re: Share TADOConnection between usersessions?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2014 8:36 AM   in response to: Daniel Fields in response to: Daniel Fields
Daniel Fields wrote:
I found the answer. No! ADO is COM based technology that uses permanent, internal threads. You have to create one for each session, which means it goes into the UserSession. That makes sense because of ADO's age. There are plenty of newer and third-party options to access data.

Here is the source
http://stackoverflow.com/questions/1241844/is-delphis-tadoconnection-thread-safe

Thanks. I was afraid of that but when I searched I didn't hit this link.

Rats. Oh, well, it's not that it won't work. I'll just have to use a connection per user for now. I'll look into pooling the connection somehow later.

Dan
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02