Page 1 of 1

Random invalid results coming back for data reader

Posted: Tue 26 May 2009 21:04
by tomcat2001
We are using the 4.0 version of the drivers.

What the problem we are currently experiencing is randomly we'll have an invalid data reader returned. By invalid I mean I ask for it to return me columns such as patientid, ssn, bdate and instead what I get back in my datareader is a single column and the column is labelled id. So since it is randomness, that sort of leads me to believe threading. We do have parts of our application that is threaded. But the areas we are getting the errors in are part of the main thread. Since I'm sure this will be asked, here's how we're working with connections in the threaded environment.

We have a helper method that basically instantiates a new instance of a pgsqlconnection object and opens it. It also creates a command object and sets the query to execute. It then returns the data reader. We are not using a shared connection. So we do not think this will cause any problems in a threaded environment because we are not reusing the connection object itself. We are using connection pooling and since we do create so many new connection objects, turning that off is NOT an option.

In addition, we do not have a sample project that we can show and even if we did, as I mentioned this is random. Meaning somebody may get it once every couple of days.

As a side note our application did not have this problem in our previous version when we were using the 3.75 drivers.

Any advice on what to look for or considerations in threaded environments would be helpful given the current situation I described.

Posted: Wed 27 May 2009 13:33
by Shalex
This problem can occur if the same connection object is used in several threads, for example. If you don't use the connection object asynchronously, please lock it when using it. Does it help?

Posted: Wed 27 May 2009 13:39
by tomcat2001
While I appreciate the feedback, in my original post I stated that we are not actually using the same connection instance in multiple threads. We do have multiple threads, but the connection instances are not being shared.

Posted: Wed 27 May 2009 16:33
by Shalex
Anyway, try to lock the connection object while reader is using it. If it doesn't help, we need a test project to reproduce the problem.