SPONSORS:






User Tag List

Results 1 to 3 of 3
  1. #1
    Member
    Join Date
    Mar 2001
    Location
    nashville, tn, usa
    Posts
    86
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error: Invalid database handle

    Any ideas how to solve this issue? The details are:

    1. There is an include file that has the following declared:
    HDATABASE hdbc = DB_Connect ("dsn=dat_automation_data")
    HSQL hstmnt

    2. There is a test script file that has a main() script that executes 2 scripts.

    script1 calls function1. function1 has
    hstmnt = DB_ExecuteSql (hdbc, "SELECT blah1...")
    while DB_FetchNext (hstmnt, rRec)
    ...
    DB_FinishSQL (hstmnt)
    DB_Disconnect (hdbc)

    script2 calls function2. function2 has
    hstmnt = DB_ExecuteSql (hdbc, "SELECT blah2...")
    while DB_FetchNext (hstmnt, rRec)
    ...
    DB_FinishSQL (hstmnt)
    DB_Disconnect (hdbc)

    Both function1 and function2 use the hdbc and the hstmnt, but the actual SQL statement differs between the two. When function2 gets to the DB_ExecuteSQL line, the following error occurs.

    *** Error: Invalid database handle
    Occurred in DB_ExecuteSql

    Any ideas what causes the errors?

    I have found the following workaround. If
    HDATABASE hdbc = DB_Connect ("dsn=dat_automation_data")
    HSQL hstmnt
    are moved from the other include file to within each of the individual functions, the error does not occur.

    Because there are so many functions using the HDATABASE hdbc = DB_Connect ("dsn=dat_automation_data")
    HSQL hstmnt, I would like to only declare them once for maintainability. Thanks for the help.

    ------------------


    [This message has been edited by joe_dickason (edited 12-13-2002).]

  2. #2
    Member
    Join Date
    Mar 2001
    Location
    nashville, tn, usa
    Posts
    86
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Error: Invalid database handle

    Have determined this is a global versus local variable issue.

    If the HDATABASE hdbc = DB_Connect ("dsn=dat_automation_data") and HSQL hstmnt are global, then it seems

    DB_FinishSQL (hstmnt)
    DB_Disconnect (hdbc)

    also needs to be done only once. currently, the finish & disconnect is done within each function.



    ------------------

  3. #3
    Senior Member
    Join Date
    Aug 1999
    Location
    Cambridge, UK
    Posts
    470
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Error: Invalid database handle

    For a long time we have had our scripts set up to have one global database handle, which is opened (using DB_Connect) in TestCaseEnter(), and closed in TestCaseExit (with suitable exception handling). For each sql query that is executed, you only then need to call DB_ExecuteSql, DB_FetchNext (possibly more than once) and DB_FinishSql.

    I would definitely recommend calling DB_FinishSql after each query executed; it's good practice to closed down any resources that you won't subsequently need in your testcase.

    ------------------

 

 

Posting Permissions

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

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 10:56 AM.

Copyright BetaSoft Inc.