Forum Discussion

ajohnson2020's avatar
ajohnson2020
Contributor
15 years ago

Changing DBTables database target without changing data

I am running TestComplete 7.51, and use some DBTables stores that reference data generated during some of my tests.

When we go into a new major software release I copy the database under a new name for subsequent development,

keeping the old database for testing of customer issues and service packs.  My TestComplete project is copied to

the new code repository branch at the same time, and I want to point my new project to the data in the new database.



It's kind of a pain to have to step through the test that each DBTable store references to recapture the data that I know hasn't changed, just to change the database name.  Is there a way to change just the connection data without forcing a new database query?

Even better would be a way to have a single connection string for the whole DBTables collection, which I guess is a feature wish for a later version.



Allen

4 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    When you get your DBTables object, you can set the connection string dynamically in the scripts.  We're doing something similar in that we can run the same project on multiple environments where the SQLServer name changes (not necessarily the table name).  Here's our routine that does the compare.



    procedure CompareWebTables;



        var

            I: Integer;

            TableConnectionString: String;

            RecordSet;

            DBTableObj;



        begin

        RecordSet := DDT.CSVDriver(ScriptDirectory + '\Script\WebTableNames.csv');

        

        TableConnectionString := ConnectionString + LocalDBName + 'Data Source = ' + ServerName + '; LoginPrompt := False;';

        Log.AppendFolder('SQL Web File Comparisons:');

        try

            while not RecordSet.EOF do begin

                Log.AppendFolder(RecordSet.Value['TableName']);

                DBTableObj := Evaluate('DBTables.' + RecordSet.Value['TableName']);

                DBTableObj.ConnectionString := TableConnectionString;

                DBTableObj.Compare;

                Log.PopLogFolder;

                RecordSet.Next;

                end;

        finally

            Log.PopLogFolder;

            Indicator.Clear;

            if IsAssigned(RecordSet) then DDT.CloseDriver(RecordSet.Name);

            if ExceptionMessage <> ''

                then ProcessError('The following error occured while comparing Web files: ' + ExceptionMessage, TRUE);

            end;

        end;
  • Thanks Robert!  I had overlooked the DBTables connection string, that should work nicely.



    Allen
  • liuhsiu's avatar
    liuhsiu
    New Contributor
    Hi, Robert



    I got same question here.   However, do you have C# code for the codes you wrote for the top question?



    The following scripts throw me a run time error.   I think it's connection string.



    I want to changing DBTables database target without chaning data.



    When I record the table, the connection string is hard coded for the database name and computer name.



    Could you help me to correct it?    Thanks for help!




    function VerifyDBTable( )

    {


    VerifyDBTable( )

    var DBTab = DBTables["TC000008_Table"];


    var DBName = "myNewDatabaseName";


    var computerName = "myComputerName";


    DBTab["ConnectionString"] = 'Provider=SQLNCLI10.1;Integrated Security=SSPI;Persist Security Info=False;User ID="";Initial Catalog=' + DBName + ';Data Source=' + computerName + ';Initial File Name="";Server SPN="";';


    DBTab["Check"]();


     



    }