Welcome to MSDN Blogs Sign in | Join | Help

IDisposable

Bill Wagner's article on IDisposable is interesting. From all objects that implement this interface, my favorite is always database access objects (like SqlConnection). For a long time, I've been discussing with our brilliant architect Ed Jezierski about this.

Why should a developer building "business solutions" ever care about closing a connection to a database, or even opening it?

The "using" statement is one step forward, but not enough in my opinion. In the same way you need to remember closing a connection, you need to remember using "using".

Also, the "connection string" is usually a place where all sort of really low level parameters are declared (like pooling options, timeouts, etc.). if you think about it, all these are really very important aspects of the application that are usually essential for the stability, robustness and performance of not just one module, but the whole application.

Forgeting to close connections to a database is probably one of the silliest yet most frequent sources of problems, at least in my experience working in IT and helping customers build (and repair) business solutions. 

So the question is: should we fire all developers who forget to close connections or should we build or design something that would take care of the problem effectively?

I believe this falls into the broader category of "concerns" that don't belong to the business solution level. In my opinion, a developer (again, those building business components) should never care about dealing with this. 

Of course somoene has to take care of it, but I insist not the developer. The underlying architecture of the solution should provision all this and act defensively in case things don't happen as expected.  

To be continued...

Published Saturday, December 18, 2004 10:14 PM by eugeniop
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: IDisposable

Yes, I totally agree!
Saturday, December 18, 2004 11:00 PM by Uwe Keim

# re: IDisposable

A good code-gen framework or OR Mapper will handle this automatically for the developer.
Sunday, December 19, 2004 7:51 AM by Paul Wilson

# re: IDisposable

A simple data access layer can ensure connections are always closed eventually. Thats pretty much all u gotta do !!
Sunday, December 19, 2004 10:04 AM by Sahil Malik

# re: IDisposable

The code gen approach may help, closing connections. In any case it is an underlying framework. Which is fine.
Sunday, December 19, 2004 10:30 AM by "simple data layer"...

# re: IDisposable

If it were a "simple" data access layer, then why people forget? Because they don't use one? In either case, the decission to use a DAL is part of using a framework: understood as a way of standardizing development
Sunday, December 19, 2004 10:33 AM by Disagree w Sahil

# Eugenio Pace Software as a Service Architecture Guidance IDisposable | fix my credit

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker