开发者

Large number of open connections to database crashes the application

开发者 https://www.devze.com 2023-02-15 14:17 出处:网络
In my web service, i connect to Sybase database. I have list of Doctors and each doctor can be associated with number of Hospitals. I need to update a few details on every Hospital with which a Doct

In my web service, i connect to Sybase database.

I have list of Doctors and each doctor can be associated with number of Hospitals. I need to update a few details on every Hospital with which a Doctor is working.

For every doctor a new connection to database is opened.For every Doctor in a list, I first get the list of Hospitals in the DbReader and i do operations on each Hospital in the reader. Once all the records in the DbReader are processed, I close the reader along with the connection. (This is because i pass System.Data.CommandBehavior.CloseConnection to the ExecuteReader() method of the Sybase.Data.AseClient.AseCommand class)

Now, if the number of doctors are beyond some limit, I get errors开发者_JAVA百科 since the number of connections which are open become very large.

Which different approach can i use in this scenario to get rid of the error? How to know the number of open connections from client side?

One of the thing i can do is - don't open a new connection until previous connection is closed. But this approach is not that good (I think) because, though multiple connections are allowed, i'll be having one connection at a time.


Why not using connection pooling? or implement a singleton connectionmanager which provides new connections as long as the limit is not reached.

Besides are you sure you need Multiconnection in this case? it sounds like you have to run the same process for each Doctor. So you can do it in a loop, guess one connection will be enough for that.

0

精彩评论

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

关注公众号