Code to change ODBC timeout

Posted on 2014-07-16
Last Modified: 2014-07-17
I have a client with multiple applications with dozens and dozens of queries where I need to change the ODBC timeout. Rather than go into each query is there some code I can run to do this for me? It'd save me a ton of time.

Thanks Experts!
Question by:Ei0914
    LVL 84

    Accepted Solution

    You can do it with DBEngine:

    Dim db As DAO.Database
    Set db = DBEngine(0)(0)
    db.QueryTimeout = 200 ' or whatever value works for you

    Or you can set it in the Registry. See this Article:

    Author Comment

    OK Cool. I found the registry suggestion and am doing that. Do you know if this then overrides the timeouts in each of the queries??
    LVL 84
    Yes, it works for all queries. It also is a persistent setting, meaning you only have to change it once, and it'll "stick"
    LVL 56

    Expert Comment

    by:Jim Dettman (Microsoft MVP/ EE MVE)
    I'd double check that.  I'm not sure that article is correct, but it is the engine key, so maybe it does.

     But I believe like all other settings there it will require a close and re-open of Access.   It's not something your going to be able to set on the fly.   Also the article says "If greater" and I'm wondering if your currently set to 60 (the default) and then set the registry to 0 (no timeout) if it's going to honor that or not.

     Personally, I'd set the set the timeout directly on the querydef object (which is what I do) so there's no question about what's being used.   Any setting there will over ride anything else.

    LVL 84
    Sorry, should have been more clear:

    If you set the Registry entry it would stick. You'd need to run the DBEngine code each time the app is started in order for that to work.

    Author Comment

    So - in each front-end upon open I need to run the above code? I just want to make sure I understand.
    LVL 56

    Expert Comment

    by:Jim Dettman (Microsoft MVP/ EE MVE)
    Or the following as a one time thing:

      Dim db As DAO.Database
      Dim myQueryDef As DAO.QueryDef
      Dim intI As Integer

      Set db = DBEngine.Workspaces(0).Databases(0)

      For intI = 0 To db.QueryDefs.Count - 1
        Set myQueryDef = db.QueryDefs(intI)
        Debug.Print "> "; myQueryDef.Name
        myQueryDef.ODBCTimeout = 60
      Next intI

      This sets the queries individually.  Note however that it doesn't apply to SQL you execute in code.   Those reply on the DB and registry settings.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
    Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now