How to properly handle keep connection open

Posts   
 
    
miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 23-Oct-2012 09:03:01   

Hi,

is there a need to use a method adapter.CloseConnection(); in case I'm using KeepConnectionOpen and adapter is in using clause ?

Other words: does Dispose on adapter will do the same as CloseConnection() ?

Best Regards, MiloszeS I

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 23-Oct-2012 12:29:00   

miloszes wrote:

Hi,

is there a need to use a method adapter.CloseConnection(); in case I'm using KeepConnectionOpen and adapter is in using clause ?

Other words: does Dispose on adapter will do the same as CloseConnection() ? Best Regards, MiloszeS I

Dispose does close a connection, but it also rolls back an open transaction. If you use KeepConnectionOpen, it's best to simply call CloseConnection() when you are done with the work, because it keeps the connection open only long enough to do the work. This frees up resources at that moment (connection goes back to the pool). When you wait till Dispose, the connection might stay open longer than needed.

Frans Bouma | Lead developer LLBLGen Pro
miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 23-Oct-2012 13:20:49   

Does it work properly (is it really closed when CloseConnection is called)?

I've got a strange behavior in the production environment (postgresql 9.2.1). In case I've switched the flag to true, after about 2 minutes I've got a problem with getting the connection from the pool.

an error has occurred during retrieving lock information. Timeout while getting a connection from pool.;Timeout while getting a connection from pool.StackTrace: at Npgsql.NpgsqlConnectorPool.RequestPooledConnector(NpgsqlConnection Connection) in C:\projects\Npgsql2\src\Npgsql\NpgsqlConnectorPool.cs:line 228 at Npgsql.NpgsqlConnection.Open() in C:\projects\Npgsql2\src\Npgsql\NpgsqlConnection.cs:line 543

It's probably the driver fault (I've already requested a ticket at pgfoundry), but just want to ensure that its correctly (am I doing it ok) handled from LLBLGen site. I've tested it with npgsql 2.0.12 as well as 2.0.11.93 and the problem only exists, when I set

adapter.KeepConnectionOpen = true;

Regards, MiloszeS

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 24-Oct-2012 00:57:05   

Must be a driver's issue.

P.S. could you try setting the flag in the CTor of the Adapter.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 24-Oct-2012 10:53:42   

It also might be your pool is full because no connection is closed and therefore placed back into the pool. Be sure to use the latest build of our runtime and make sure you call CloseConnection when keeping the connection open OR make sure you dispose the adapter.

Frans Bouma | Lead developer LLBLGen Pro
miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 25-Oct-2012 09:39:28   

Thanks for a tip - I'll try it on monday (passing a KeepConnection... by a constructor). Currently system must be high available and a problem exists only in the production environment.

We're always dispose a adapter. I've also tried with directly call CloseConnection() but it didn't helped. I also think that it could be a driver problem.

Best Regards, MiloszeS

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 25-Oct-2012 12:01:34   

Ok, we'll await your results on monday

Frans Bouma | Lead developer LLBLGen Pro
miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 29-Oct-2012 14:25:01   

Yep,

the same problem exists event if I pass the keepConnOpen via constructor.

Regards, MiloszeS