Forum Discussion

katleemn's avatar
katleemn
New Contributor
15 years ago

Object Required dbConnection

We're new to TestComplete and are trying to bring as much of our existing architecture over as possible.



We use an MS-Access back end for data, and I'm right now writing and calling a sub that opens a connection to that database.  The OPEN_CONNECTION function is called from another script (using the USEUNIT statement) and is not erroring.  When I try to query that database, however, I get an exception error:  Object Required dbConnection.



The last line of code is the one erroring - can anyone help me figure this out?  Oh, I have tried defining dbConnection within the GET_DATA, Main, and the Common.OPEN_CONNECTION functions, but it doesn't appear to help.  Thanks in advance for your help with a newbie question!



'USEUNIT Common

Sub Main

   

  GET_DATA


End Sub


Sub GET_DATA


  Common.OPEN_CONNECTION   


  VI_TESTSET = "CSS001"

    Log.Message("Test Set is: " & VI_TESTSET)


  Set rsTestSetDB = CreateObject("ADODB.Recordset")

  Set rsTestSetDB = dbConnection.Execute("SELECT * FROM TestSets WHERE TestSetID LIKE '" & VI_TESTSET & "%%% ' " & "ORDER BY TestSetID")  


End Sub






1 Reply

  • Hello Kathryn 



    Your dbConnection should be a global variable when you are defining it in one script and using it in another script.





    Try this




    Set dbConnection = CreateObject("ADODB.Connection")


    dbConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;" & "Data Source=C:\MyTestData.mdb"


    dbConnection.Open


    Set Cmd = CreateObject("ADODB.Command")


    Cmd.ActiveConnection = dbConnection


    Cmd.CommandText = "SELECT * FROM TestSets WHERE TestSetID LIKE '"
    & VI_TESTSET & "%%% ' " & "ORDER BY TestSetID
    "


    Cmd.CommandType = adCmdText


    Set rsTestSetDB= Cmd.Execute





    Thankyou