denolfe
12 years agoOccasional Contributor
Variable for connection string or Data Source Name?
Hello,
I have been dynamically building my database connection string through scripting as I perform testing on SQL 2005, 2008, and 2012, which all could have a different SQL Driver.
I am now seeing the need to create Database Checkpoints as opposed to checking specific values. The problem I am running into is that when creating the DB Checkpoints, TestComplete requires me to either enter a Data Source Name or enter a connection string, both of which could be different based on which machine the testing is occurring on.
So my question is, is there a way to pass a variable for the connection string or the Database Source Name for these checkpoints? Is there a better way to do this, like populate a temporary table from a query then compare that to a data object?
Any help is appreciated.
Code for retrieving the connection string:
I have been dynamically building my database connection string through scripting as I perform testing on SQL 2005, 2008, and 2012, which all could have a different SQL Driver.
I am now seeing the need to create Database Checkpoints as opposed to checking specific values. The problem I am running into is that when creating the DB Checkpoints, TestComplete requires me to either enter a Data Source Name or enter a connection string, both of which could be different based on which machine the testing is occurring on.
So my question is, is there a way to pass a variable for the connection string or the Database Source Name for these checkpoints? Is there a better way to do this, like populate a temporary table from a query then compare that to a data object?
Any help is appreciated.
Code for retrieving the connection string:
function GetConnectionString()
{
var Connection;
var Key, ValueName;
var regEx, SQLVersion, SQLDriver;
// Gets an object for the Windows system registry key
Key = Storages.Registry("Software\\Microsoft\\MSSQLServer\\MSSQLServer\\CurrentVersion", HKEY_LOCAL_MACHINE);
// Specifies the name of the value you want to obtain
ValueName = "CurrentVersion";
SQLVersion = Key["GetOption"](ValueName, "Not Found");
regEx = /^\d*/;
// Perform search operation
Match = SQLVersion["match"](regEx);
if (Match == "9")
SQLDriver = "SQL Native Client";
else if (Match == "10")
SQLDriver = "SQL Server Native Client 10.0";
else if (Match == "11")
SQLDriver = "SQL Server Native Client 11.0";
Project["Variables"]["Connection_String"] = "Driver={"+ SQLDriver +"};Server="+ Sys["HostName"] +";Database=TWO;Trusted_Connection=yes;";
Log["Message"]("SQL Connection String: "+ Project["Variables"]["Connection_String"]);
}