Leave adapter connection open for hours?

Posts   
 
    
brianPS
User
Posts: 3
Joined: 19-Oct-2010
# Posted on: 17-Nov-2010 16:23:22   

We have a repository using the adapter pattern. Since the repo was designed for use by web applications, we just open a connection the first time the adapter is used and keep it open for the repo's whole life.

We are adapting the repo for use by a windows service. Leaving the connection open makes me nervous. Is there an official recommendation on this stuff? We can always recreate the repo every n seconds as the service spends most of its time idle.

Thanks!

B

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 17-Nov-2010 17:22:47   

creating an adapter is really very lightweight (almost instantly), so I'd really opt for closing the connection when you're done and also not keep the adapter around. Especially in a web scenario, as multiple requests will be executed on multiple threads which means you will run the risk of sharing the adapter across threads, which will cause big problems.

So what you have with a shared adapter instance and an open connection is really not what you should do.

Frans Bouma | Lead developer LLBLGen Pro
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 17-Nov-2010 17:23:52   

Whether it's a web application or a service. It's always recommended to open the connection when needed, and close it as soon as you possible.

Thanks to connection pooling, re-opening a connection should not have any impact on performance.