开发者

How do I queue database access?

I have a GUI where different parts of the information shown is extracted from a database. In order for the GUI not to freeze up I've tried putting the database queries in BackgroundWorkers. Because these access the database 开发者_JAVA百科asynchronously I get an exception telling me the database connection is already open and used by another.

Is it possible to create a queue for database access?

I've looked into Task and ContinueWith, but since i code against .Net framework 3.5 this is not an option.


What is the DB engine you're using? Most modern databases are optimized for concurrent operations, so there's no need to queue anything.

The thing you're appaently doing wrong is reusing the same IDbConnection instance across different threads. Thats a no-no: each thread has to have its own instance.


I think your problem is in the way you get a connection to the database. If you want to fire separate queries you could use separate connections for separate requests. If you enable connection pooling this does not add a lot of overhead.


Try to use the pool objects. Plus as per your description your trying to open a connection on an unclosed connection object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜