Is passing a Command object/Reader to a function a good idea?

Posted by Cyril Gupta on Stack Overflow See other posts from Stack Overflow or by Cyril Gupta
Published on 2010-04-27T09:47:26Z Indexed on 2010/06/12 14:53 UTC
Read the original article Hit count: 202

Filed under:
|
|
|

I've been getting some inexplicable errors (running out of connections from the connection pool) with MySql database with .Net 4 (C#). Till now all my attempts at finding a reason for this have been in vain. Now I also have a situation in which a lock on a table is not cleared for a long time even though all I have been doing is read operations from it.

My code looks okay (I've put all readers and connections in using blocks). The only anomaly I have is that I've been passing MySqlCommand and MySqlDataReader objects as parameters to functions who work with them.

That doesn't seem like a bad idea for me because it avoids some repetition (DRY!). But since I can't find any other explanation I have to suspect that this is causing the problem.

What do you think?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET