+ Reply to Thread
Results 1 to 3 of 3

adodb connection to sql server.. How long does it stay open when idle

  1. #1
    Forum Contributor
    Join Date
    10-02-2013
    Location
    Harrisburg, PA
    MS-Off Ver
    Office 365 MSO (16.0.10730.20264) 32-bit
    Posts
    172

    adodb connection to sql server.. How long does it stay open when idle

    Hi.
    Question. In vba... every time I run a query against an sql server, I open the connection, run my query, then close the connection. If I have One function do that, and then another function do a different query, For speed, I think it would be best to not close the connection between function calls. Maybe create a Global Connection that both functions could run against. But, how long will the connection stay open between calls??? I am worried that if I do this, at some point, the connection may go idle and error/close. Could I do a connection check to see if it is still open?

    I am all about speed - keeping my apps as fast as possible. The apps run globally and Asia's speed is slow.

    My startup will run the two functions one after the other. Both use the same connection. So, Why should I open/close the connection in the 1st sub and open/close in the next sub??

    Write_Login_History(Get_Name_From_ID()) ' query sql server to get name then write to sql server


    code example of 1st fuctions
    Please Login or Register  to view this content.
    Thanks
    Steve
    Harrisburg, PA
    Last edited by Steveapa; 03-27-2021 at 12:04 PM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,015

    Re: adodb connection to sql server.. How long does it stay open when idle

    If you have two routines run one after the other using the same connection, there isn't really any point in closing and reopening it in between. I doubt that the connection pooling on the server would have actually cleaned up the connection in that time anyway even if you did. You should avoid keeping the connection open unnecessarily, but I can't see any benefit in closing it in between two immediately consecutive routines.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    10-02-2013
    Location
    Harrisburg, PA
    MS-Off Ver
    Office 365 MSO (16.0.10730.20264) 32-bit
    Posts
    172

    Re: adodb connection to sql server.. How long does it stay open when idle

    I learned that you can check to see if the connection is still open with cn.state = 1 then connection is open while cn.state = 0 connection is closed! BOOM!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. help with ADODB.Connection
    By Ivancovish in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-07-2019, 12:10 PM
  2. Adodb Connection
    By Syed Haider Ali in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-30-2018, 08:03 AM
  3. adodb connection - server response
    By HarryKlein in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-24-2018, 01:32 AM
  4. ADODB Connection
    By kenny.fsw in forum Access Tables & Databases
    Replies: 12
    Last Post: 08-06-2015, 01:17 PM
  5. ADODB connection - Changing connection path via fileDialog
    By cajand in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2015, 08:06 AM
  6. [SOLVED] deactivating a cell after being idle for so long.
    By emilyloz in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-01-2013, 09:37 AM
  7. VBA and ADODB.Connection
    By AedanLee in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-29-2010, 06:37 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1