Hi there - I am experiencing
EXACTLY the same problem.
However, this problem has only started occuring since I updated my application as per your suggestions in this thread :-
http://devart.com/forums/viewtopic.php?t=14287
Just to recap, previously I was using "Pooling=true" in my ConnectionString and I was then creating and disposing a PgsqlConnection object for EVERY database call.
Following your suggestion, I changed this to "Pooling=false" and I *only* have ONE global instance of PgsqlConection which is used throughout the application. This instance is created at program startup and disposed on termination.
Since making this change, a number of users are complaining of receiving a "Connection must be opened" error. Here is a typical Stack Trace which a user emailed me from their error report :-
Code: Select all
System.InvalidOperationException
Connection must be opened.
Server stack trace:
at CoreLab.Common.Utils.CheckConnectionOpen(IDbConnection connection)
at CoreLab.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at CoreLab.Common.DbCommandBase.AsyncExecuteReader(CommandBehavior behavior)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message reqMsg, Boolean bProxyCase)
at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed, MessageData& msgData)
at CoreLab.Common.DbCommandBase.a.EndInvoke(IAsyncResult A_0)
at CoreLab.Common.DbCommandBase.EndExecuteReader(IAsyncResult result)
at CoreLab.PostgreSql.PgSqlCommand.EndExecuteReader(IAsyncResult result)
at ClinicOffice.cDB_PGSQL.FillTable(DataTable Table, String SQL)
at ClinicOffice.cDB.GetDataRow(String SQL)
at ClinicOffice.cController.CheckStillLoggedOn()
at ClinicOffice.cController.m_timerSystem_Tick(Object sender, EventArgs e)
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
This problem never happened before this change. The only way I have managed to reproduce this problem is as follows :-
[1] Create a test app with a single global connection object (which is created and opened at startup) and button which fills a table and assigns the table to a DataView.
[2] Run the program and connect to a Postgres database on a different PC
[3] While the program is running, disable and re-enable your network card.
[4] Click the button to fill the datatable.
You will (more than likely) receive the "Connection must be opened" message or if not, you will still get an error message.
The work-around for this that I have implemented in my application is to manually call
CoreLab.Common.Utils.CheckConnectionOpen(my_con); whenever I am about to use the global connection. If that line throws an exception, I call
my_con.Close(); my_con.Open(); to re-establish the connection.
This seems to resolve the issue (for me at least). I hope this helps anyone else who is suffering from this problem.
Regards,
Hedley