Page 1 of 1

Got two type errors when fast process with multi thread whatever enable pool or not with asynchronous query execution

Posted: Sun 15 Jun 2014 10:32
by waertf
got the error msg below:
System.InvalidOperationException: Connection must be opened.

Server stack trace:
at Devart.Common.Utils.CheckConnectionOpen(IDbConnection connection)
at Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior,
Boolean nonQuery)
at Devart.Common.DbCommandBase.AsyncExecuteReader(CommandBehavior behavior)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(
IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInCont
ext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMe
ssage 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, Messa
geData& msgData)
at Devart.Common.DbCommandBase.a.EndInvoke(IAsyncResult A_0)
at Devart.Common.DbCommandBase.EndExecuteReader(IAsyncResult result)
at Devart.Data.PostgreSql.PgSqlCommand.EndExecuteReader(IAsyncResult result)
at PostgresqlTest.SqlClient.get_DataTable(String cmd) in D:\alonso\mups\Postg
resqlTest\SqlClient.cs:line 170
at PostgresqlTest.Program.sqlTest() in D:\alonso\mups\PostgresqlTest\Program.
cs:line 74
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, C
ontextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
got the below error with code

Code: Select all

PgSqlDataReader myReader = command.EndExecuteReader(cres);
Devart.Data.PostgreSql.PgSqlException: Transport channel is closed. ---> Devart.Common.i: Transport channel is closed.
at Devart.Common.a0.e(Byte[] A_0, Int32 A_1, Int32 A_2)
--- End of inner exception stack trace ---

Server stack trace:
at Devart.Data.PostgreSql.s.b(Exception A_0)
at Devart.Common.a0.e(Byte[] A_0, Int32 A_1, Int32 A_2)
at Devart.Data.PostgreSql.y.a(Byte[] A_0, Int32 A_1, Int32 A_2)
at Devart.Data.PostgreSql.y.h()
at Devart.Data.PostgreSql.v.b(Boolean A_0)
at Devart.Data.PostgreSql.v.g(t A_0)
at Devart.Data.PostgreSql.v.f(t A_0)
at Devart.Data.PostgreSql.t.n()
at Devart.Data.PostgreSql.PgSqlCommand.InternalPrepare(Boolean implicitPrepare, Int32 startRecord, Int32 maxRecords)
at Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior, Boolean nonQuery)
at Devart.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.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 Devart.Common.DbCommandBase.a.EndInvoke(IAsyncResult A_0)
at Devart.Common.DbCommandBase.EndExecuteReader(IAsyncResult result)
at Devart.Data.PostgreSql.PgSqlCommand.EndExecuteReader(IAsyncResult result)
at PostgresqlTest.SqlClient.get_DataTable(String cmd) in D:\alonso\mups\PostgresqlTest\SqlClient.cs:line 165
with following project using .net 3.5 framework and smartinspect log framework:
https://drive.google.com/file/d/0B4z5i7 ... sp=sharing

Re: Got two type errors when fast process with multi thread whatever enable pool or not with asynchronous query execution

Posted: Mon 16 Jun 2014 15:21
by Pinturiccio
We have studied your example. dotConnect for PostgreSQL is not thread safe, so you should use a separate connection for each thread or synchronize the threads yourself. For example, you have the following line in your code:

Code: Select all

//lock (lockSql)
If this line is uncommented, the errors don't occur, and your application works correctly.