Prev: Need to normalize some tables after database has been split
Next: Reminder - Microsoft Responds to the Evolution of Community
From: Banana on 24 May 2010 16:02 On 5/24/10 12:38 PM, Tony Toews [MVP] wrote: > "Dirk Goldgar"<dg(a)NOdataSPAMgnostics.com.invalid> wrote: > >> If you're going to use the connection more >> than once in a procedure, it's better to define and set a Connection object, >> but if you're only going to use it once, you don't need to. > > Why is it better? Save time? > > Tony Simply because Connection is a relatively expensive object to create/destroy - it's cheaper to keep a existing connection alive and re-use it than it is to close and re-open connection on the demand. Granted, one could go too far and end up holding dead connection which is bad for the server but that's why we have the saying, "moderation in everything." ;)
From: Tony Toews [MVP] on 24 May 2010 17:29 Banana <Banana(a)Republic> wrote: >>> If you're going to use the connection more >>> than once in a procedure, it's better to define and set a Connection object, >>> but if you're only going to use it once, you don't need to. >> >> Why is it better? Save time? >> >> Tony > >Simply because Connection is a relatively expensive object to >create/destroy - it's cheaper to keep a existing connection alive and >re-use it than it is to close and re-open connection on the demand. >Granted, one could go too far and end up holding dead connection which >is bad for the server but that's why we have the saying, "moderation in >everything." ;) But if it's the currentproject connection it should always be present therefore next to no time/resources to create. Just use the object. Tony -- Tony Toews, Microsoft Access MVP Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/ For a convenient utility to keep your users FEs and other files updated see http://www.autofeupdater.com/ Granite Fleet Manager http://www.granitefleet.com/
From: Banana on 24 May 2010 21:12 On 5/24/10 2:29 PM, Tony Toews [MVP] wrote: > But if it's the currentproject connection it should always be present > therefore next to no time/resources to create. Just use the object. > > Tony Now I'm thinking I need to re-take grammar school and work on my reading comprehension. I thought Dirk's response was to do with opening a connection against a linked source, not CurrentProject.Connection, but he never said anything about linked source. Yes you're right - creating a object to do what CurrentProject.Connection does not really make sense. At least, one could just use a With block to cut on fairly verbose length of the invocation.
From: Tony Toews [MVP] on 24 May 2010 22:54 Banana <Banana(a)Republic> wrote: >> But if it's the currentproject connection it should always be present >> therefore next to no time/resources to create. Just use the object. >> >Now I'm thinking I need to re-take grammar school and work on my reading >comprehension. Happens to me a fair bit too. Just search for my name and look for keywords such as Oops or sorry or Duhhh. Hehehe Tony -- Tony Toews, Microsoft Access MVP Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/ For a convenient utility to keep your users FEs and other files updated see http://www.autofeupdater.com/ Granite Fleet Manager http://www.granitefleet.com/
From: Dirk Goldgar on 25 May 2010 06:49
"Tony Toews [MVP]" <ttoews(a)telusplanet.net> wrote in message news:ocllv59p5s7eq4e225skm30g8a326aiues(a)4ax.com... > "Dirk Goldgar" <dg(a)NOdataSPAMgnostics.com.invalid> wrote: > >>If you're going to use the connection more >>than once in a procedure, it's better to define and set a Connection >>object, >>but if you're only going to use it once, you don't need to. > > Why is it better? Save time? It's not a big deal, but I see two reasons: 1. Dereferencing cost. Although this is purely theory, I figure there's a cost for ever "dot" you traverse. "CurrentProject.Connection.Execute" = two dots. "objConnection.Execute" = one dot. But it costs a dot for "Set objConnection = CurrentProject.Connection", so it's not worth doing for a single use of the object. 2. Code simplicity. The fewer words in the code, the easier it is to read and maintain. That's another reason to favor "With" blocks over declaring and setting an object variable. -- Dirk Goldgar, MS Access MVP Access tips: www.datagnostics.com/tips.html (please reply to the newsgroup) |