Hi.
I have a problem with an OLEDBConnection object that is supposed to serve for
a number of clients that need data from my Access(mdb) database.
These clients are placed in different threads and try to load data from this
connection. The problem is that when the connection is retrieving data for
one of them, another one may ask for data. This throws an
InvalidOperationException with the following message:
"ExecuteReader requires an open and available connection. The connection's
current state is Open, Executing."
I fully understand its meaning, but what can I do to solve this issue?
I tried a delaying loop, checjing to see if the exception occurs again in
the loop,
and repeating the operation again. Although I used Application.DoEvents (you
know what that does) , but a loop takes all the CPU time available, and it
seems to me that the whole operation becomes very very slow and surprisingly,
memory consuming!
Any one got an idea?
Thank you all.
Chris - 30 Aug 2005 01:45 GMT
> Hi.
> I have a problem with an OLEDBConnection object that is supposed to serve for
[quoted text clipped - 14 lines]
> Any one got an idea?
> Thank you all.
Why not have each thread open its own connection or they need to wait
until the first read is done before using that connection again. What
are you doing that is eating all your cpu? If you are doing this many
connections you probably should rethink your database. Move from access
to msde or mysql.
Chris
Ehsan - 30 Aug 2005 23:07 GMT
Thanx Chris.
The problem is that our project is almost done and I don't have time to
redesign my database.
Nevertheless, I think there should be a better solution for it. Opening a
number of connections is quite impossible because I may have over 300 threads
trying to connect and as you know, connections are expensive. The CPU-hungry
part of my program is where I re-try to read from the database when I realize
that my connection is busy. That part is located in a loop. It gives the
connection a number of milliseconds to finish its job, and retries its own
operation. Yet, the performance
is awfully low.
Still looking forward to hear from you.
Ehsan.
> > Hi.
> > I have a problem with an OLEDBConnection object that is supposed to serve for
[quoted text clipped - 22 lines]
>
> Chris
Daniel Wilson - 31 Aug 2005 17:52 GMT
I have to agree w/ Chris. If you're having performance problems during
development, you'll have performance nightmares in production. Moving to
MSDE now is less painful than doing so after a bunch of customers are
screaming at you and you also have to migrate their data.
dwilson
> Thanx Chris.
> The problem is that our project is almost done and I don't have time to
[quoted text clipped - 35 lines]
> >
> > Chris
Ehsan - 31 Aug 2005 23:26 GMT
Sorry guys, there is a misunderstanding here.
This is not an ASP project. I told you the worst situation. This project
will never have 500 clients trying to connect to it exactly at the same time.
I just want it to be ready for 500 clients, thats all. I know I've chosen the
right technology, I am just asking for a way to use it correctly.
Please tell me when I can find out when my Connection becomes available
again to be used.
Thanx.
Gerrit H - 01 Sep 2005 10:34 GMT
Assuming that there are multiple threads in a single process wanting to
access the database:
Keep the connection in one thread. All other threads call that single
thread. Use an async. systeem (with callbacks) and queueing to keep track of
requests from threads and allow them to take it's turn using the connection.
Just be sure to keep optimize the database connection (indexes etc) in the
threads to keep the request to a minimum and a dataset in stead of a
datareader to process the data otherwise the connection will be kept busy by
one thread. Retrieve the required data in the callback and allow the
connectionthread to continue with the queue. Optionally you could allow the
connectionthread to open two connections for more connections shares among
the threads.
Prevent throwing exceptions, as they are expensive in resources.
Other (more expensive) option is to create a three-tier environment using
the same system as described above, if multiple connection to a database is
a problem. That way you could cache results for multiple clients wich
increases the chances of a cachehit. (webservice uses cache by design, a
good middletier component)
Hope it helps...
Gerrit
> Sorry guys, there is a misunderstanding here.
> This is not an ASP project. I told you the worst situation. This project
[quoted text clipped - 6 lines]
> again to be used.
> Thanx.
Ehsan - 01 Sep 2005 23:05 GMT
Thanks Gerrit.
I had this idea of sending messages between threads in mind and it makes me
more confident about deciding to do this.
Your post was really useful.
Thanx again.