Submit Your Article Forum Rules

Results 1 to 3 of 3

Thread: Losing ODBC connection with Pass-through query. (MS Access/Sql Svr 2008/VBA)

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    2

    Losing ODBC connection with Pass-through query. (MS Access/Sql Svr 2008/VBA)

    I am using ms access as a frontend & sql svr 2008 as a backend. The same pass-through query is being executed at two different points in the vba. The first time it executes with no problem. The second time it tries to execute but fails due to an odbc connection error. The only way I can run the pass-through query again is by closing and reopening the ms access database.

    Desparately need help.

    Thx!

  2. #2
    WebProWorld MVP DaveSawers's Avatar
    Join Date
    Dec 2006
    Location
    Lunenburg, Nova Scotia, Canada
    Posts
    760
    Then presumably the ODBC connection goes out of scope.

    What is the returned error?
    Dynamic Software Development
    www.activeminds.ca

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    2
    Returned error is as follows:

    "ODBC--connection to 'SVRabc' failed."

    Code is as follows:

    'first time works
    Dim qd1 As QueryDef
    Set qd1 = CurrentDb.QueryDefs("qrytmptblBookingsDelete")
    Dim strSQL1 As String
    strSQL1 = "delete from tmptblBookings"
    CurrentDb.QueryDefs("qrytmptblBookingsDelete").SQL = strSQL1
    qd1.Connect = getConnectionString()
    CurrentDb.Execute ("qrytmptblBookingsDelete")
    qd1.Close

    'misc code here

    'second time doesn't work
    Dim qd2 As QueryDef
    Set qd2 = CurrentDb.QueryDefs("qrytmptblBookingsDelete")
    Dim strSQL2 As String
    strSQL2 = "delete from tmptblBookings"
    CurrentDb.QueryDefs("qrytmptblBookingsDelete").SQL = strSQL2
    qd2.Connect = getConnectionString()
    CurrentDb.Execute ("qrytmptblBookingsDelete")
    qd2.Close

    After this error occurs, I can even go directly to that query, manually input the odbc connection string, try running it, & the same error still appears. The only way to correct it is to close the database & reopen it.
    Last edited by deepsand; 01-19-2012 at 09:44 PM. Reason: merged traffic flow

Tags for this Thread

Posting Permissions

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