Is This A Safe Practice (ADO.NET SqlConnection Management)?

  • Thread starter Thread starter Jeff S
  • Start date Start date
J

Jeff S

I'm considering creating a static "helper" class that will be called by
practically all methods in my data access layer (DAL) class. Rather than
having every method in the DAL create its own connection object and then
open it, I was thinking it might be good to create a static method in the
helper class that returns an opened SqlConnection object to the calling DAL
methods. The calling DAL method would then be responsible for closing and
disposing of the SqlConnection when it's done using it.

Good? Bad? Ugly? Recommendations?

Thanks.
 
Jeff S said:
I'm considering creating a static "helper" class that will be called by
practically all methods in my data access layer (DAL) class. Rather than
having every method in the DAL create its own connection object and then
open it, I was thinking it might be good to create a static method in the
helper class that returns an opened SqlConnection object to the calling DAL
methods. The calling DAL method would then be responsible for closing and
disposing of the SqlConnection when it's done using it.

Good? Bad? Ugly? Recommendations?

Good.

using (SqlConnection c = DALHelper.connect())
{
...

}

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top