No, the connection is NEVER closed. It is opened at startup and disposed at on termination of the application. To be specific, I have a DATA class which encapsulates all DB functions. This class has a public DbConnection property (called Connection). The Connection property 'getter' is as follows :-Maybe connection is closed before it is used somewhere in your code. Please review your code.
Code: Select all
get
{
if (m_connection == null)
{
m_connection = new PgSqlConnection(m_constr);
m_connection.Open();
}
return m_connection;
}
HOWEVER...
I have now changed my code back so that the ConnectionString contains "Pooling=true" (it was false with the previous code) and the getter code now reads as follows :-
Code: Select all
get
{
PgSqlConnection con = new PgSqlConnection(m_constr);
con.Open();
return con;
}
The result? NO PROBLEMS. Clearly there is an issue when applications hold on to a single connection object and keep it open throughout the lifetime of the application.
However, I am sure that you accept there clearly is a problem? I am not your only customer with this issue. leeottaway, AndreyR, irimawi and phoebe007 have all also reported the exact same problem (and I would bet there are others watching this forum with the same problem who haven't weighed in).>> We cannot reproduce the "Connection must be opened" issue.
Please also bear in mind I myself can't reproduce the problem on my network (apart from by disconnecting the cable), but about 50% of my clients are experiencing this issue and I have observed the error on their systems when it occurs.
Perhaps it might be wise to revise the advice given in this post :-
http://devart.com/forums/viewtopic.php?t=14287
... and to suggest that developers use "Pooling=true" and that we create/dispose of PgSqlConnection objects explicitly as and when they are needed?
Kind Regards,
Hedley