Forum Discussion

mohanakshi's avatar
mohanakshi
Contributor
14 years ago

TestComplete and Database

Hi,

    -->    Can we have interaction with the Database using vbscript in Testcomplete... and How can we do it...

   -->     Can we create new DB and Tables for it through Testcomplete coding.. Please help me in This

   -->     Can we create any forms in Testcomplete







Thanks in Advance,



Regards,

Mohanakshi


  • Anonymous's avatar
    Anonymous
    Hi Mohanakshi,



    -->    Can we have interaction with the Database using vbscript in Testcomplete... and How can we do it...

     

    I recommend that you read the Working With Databases article. There you can find several approaches describing how to work with databases.





    -->     Can we create new DB and Tables for it through Testcomplete coding.. Please help me in This

     

    There are several examples in our How To section which demonstrate how to do this. Please refer to the Create and drop SQL databases, Create SQL tables and Add records to an SQL table articles.
     





    -->     Can we create any forms in Testcomplete

     

    In the User Forms help topic, you can find all the needed information.
  • kenhepworth's avatar
    kenhepworth
    Occasional Contributor
    Hi Tracey,



    I am entering into this because I still seem to be having problems creating the database after going through the "Create or Drop SQL Database" code. I know it is not a problem with the connection string as I have been able to connect and get a list of the existing databases there as a test.



    I have the following code which just does not seem to work, are you or somebody able to assist?




    Sub Test

      Dim i, databaseName, commands, cmd

     

      databaseName = "TestDatabase"

     

      commands = Array("CREATE DATABASE " & databaseName)

    ',_

     '                  "DROP DATABASE " & databaseName) 

      commands(commands.length) = "CREATE DATABASE " + databaseName

      'commands(commands.length) = "DROP DATABASE " + databaseName

     

      Set cmd = ADO.CreateADOCommand

      cmd.ConnectionString =_

            "Provider=sqloledb;" & _

               "Data Source=nnnnnn;" & _

               "Initial Catalog=KENTEST;" & _

               "Integrated Security=SSPI"

      cmd.CommandType = cmdText

      i = 0

      While i < UBound(commands) + 1

        Cmd.CommandText = commands(i)

        Call Cmd.Execute

        i = i + 1

      WEnd

    End Sub



    Regards,

    Ken




  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    The problem is that TestComplete does not appear to support the use of Array and UBound.  When I attempted to run your script code, these were the two items that specifically failed to work.  To create and manipulate arrays in TestComplete use CreateVariantArray and VarArrayHighbound to work with arrays in VBScript.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    okay, did some further research and investigation and my original assessment was wrong.  The Array and UBound functions are supported in TestComplete.



    Perhaps some additional information as to what error and/or problem you're actually having would be useful.



    One thing that I did find is that commands.length is not supported.  According to VBScript reference at http://msdn.microsoft.com/en-us/library/d0t787hb(v=VS.85).aspx, the length property is only supported on a Match object.  



    In truth, I'm not sure I understand those two lines as seem to be essentially repeating what the original array declaration is doing.



    Additionally, the line setting cmd.CommandType is raising an error for me on cmdText.  I don't believe that line is necessary.



    so, if you remove those two problematic lines on commands.length and remove the line setting CommandType and you get the following which appears to work fine for me.

    Sub Test 

      Dim i, databaseName, commands, cmd 

      databaseName = "TestDatabase" 

      commands = Array("CREATE DATABASE " & databaseName)

      Set cmd = ADO.CreateADOCommand 

      cmd.ConnectionString =_ 

          "Provider=sqloledb;" &

          "Data Source=nnnnnn;" & _

          "Initial Catalog=KENTEST;" & _

          "Integrated Security=SSPI" 

      i = 0 

      While i < UBound(commands) + 1 

      Cmd.CommandText = commands(i) 

      Call Cmd.Execute 

      i = i + 1 

      WEnd 

    End Sub
  •  Interaction with external databases is all ADO access (not ADO.NET) (unless you want to write something custom in Java or .NET).  I've found google and the MSDN help files extremely helpful for looking up ADO examples when building the database access layer for my current test project.