Forum Discussion

gvkr1985's avatar
gvkr1985
Occasional Contributor
10 years ago

How to connect SQL Server using TestComplete

Hi,

 

I am trying to open SQL Server data base using my Testcomplete code-- VB Script...

 

Please Help...

6 Replies

  • Ravik's avatar
    Ravik
    Super Contributor

    TestComplete can use only 32-bit database drivers to connect databases. It does not support 64-bit database drivers. This is due to the fact that TestComplete is a 32-bit application, so it cannot load 64-bit modules into its process. Thus, in order for TestComplete to be able to access a database running on a 64-bit client machine, 32-bit database drivers must be installed on the machine.

     

    If you use the Microsoft Open Database Connectivity Data Source Administrator tool to connect to a database on a 64-bit operating system, make sure that you use the 32-bit version of the tool, Odbcad32.exe (it is in the <Windows>\SysWOW64 folder). Otherwise, the tool will not be able to detect the needed 32-bit database drivers.

     

     

  • chrisb's avatar
    chrisb
    Regular Contributor

    Look at the TC examples here: http://support.smartbear.com/viewarticle/56911/

     

    Using the ADO object works fine for me. In the exxample below I pass in a SQL query. I have another function that builds SQL queries for me to pass into this..

     

    function query (sqlQuery) {

    var dbObj = ADO.CreateADOQuery();

    dbObj.ConnectionString =  //your connection string here

    dbObj.SQL = sqlQuery;

    dbObj.Open();

    queryResult = dbObj;

    return queryResult;

    }

     

    • jasmeenkaur27's avatar
      jasmeenkaur27
      Contributor

      I tried the same code as stated:

       

      var Qry1;

      // Create a query

      Qry1 = ADO.CreateADOQuery();

      // Specify the connection string

      Qry1.ConnectionString = "Driver={Microsoft ODBC for Oracle};Dbq= FILCODU2.uk.fid-intl.com:1701/FILCODU2;Uid=xx;Pwd=xx;"

      // Specify the SQL expression

      Qry1.SQL = "Select * FROM table WHERE COMM_CODE = 'COT'";

      // Execute the query

      Qry1.Open();

      // Process results and insert data into the test log

      Qry1.First();

      while (!Qry1.EOF) {

      Log.Message(Qry1.FieldByName("columnname").Value);

      Qry1.Next();

      }

      // Closes the query

      Qry1.Close();

       

    • gvkr1985's avatar
      gvkr1985
      Occasional Contributor

      here is my code and it is not working...

       

      Sub SQLServer

      Set dbObj = ADO.CreateADOQuery()
      dbObj.ConnectionString = mil-tfsprd-01
      dbObj.Open()

      End Sub

      • chrisb's avatar
        chrisb
        Regular Contributor

        You are not doing any SQL query on the database! In the example below I have hardcoded a generic SQL query in for you to modify, you would most likely want to add a parameter to your function and pass the query in, but this should do for now.

         

        Sub SQLServer

        Set dbObj = ADO.CreateADOQuery()
        dbObj.ConnectionString = mil-tfsprd-01

        dbObj.SQL = "Select * FROM yourcolumn WHERE avalue = something";
        dbObj.Open()

        End Sub

         

        Your connection string looks odd, take a look at the link I posted above. That site has lots of information about how a connection string should be formatted. Check with your app developers they may well know the correct connection string if your app is having to connect to the database.