Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

database connection scope. Pro's Con's Suggestions

connection

  • Please log in to reply
3 replies to this topic

#1 RHankinsJr

RHankinsJr

    CC Lurker

  • New Member
  • Pip
  • 8 posts

Posted 05 November 2011 - 11:31 AM

I do not have a problem per se.

I would like advice on the pros and cons of declaring a database connection in the various scopes available to us.

What are the pro's / con's of declaring your database connection as:

Global ( open when mdi load, close when it closes )

Form wide ( connect in _load, close in _formclose )

Procedure Level ( connect only when accessing data and immediately close )

I thank you for your replies

Edit:
Vb.net and sql or ole dbs

Edited by RHankinsJr, 05 November 2011 - 02:20 PM.

  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 05 November 2011 - 06:49 PM

Usually, establishing a connection is expensive. So, if you open and close the connection frequently, it's pretty wasteful and can make your application less responsive. With that said, if your application only rarely needs to communicated with the database, it might be worthwhile to push the connection to a lower level. As always, it varies.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 RHankinsJr

RHankinsJr

    CC Lurker

  • New Member
  • Pip
  • 8 posts

Posted 05 November 2011 - 07:03 PM

Thank you for your reply.

Since you mentioned that a connection is fairly expensive I would like to ask another question.

Are any of the other database access object expensive enough that they should be global?

Also, could you suggest a source I could use to find more insightful information like this? I have many .net books and these types of things are never covered.

Thank you again.
  • 0

#4 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 06 November 2011 - 10:12 AM

Here's the thing: opening a connection to a database requires network activity, not just in memory activity. The other objects use that connection, so only have the local, in-memory costs.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download