Forum Discussion

Anurak's avatar
Anurak
New Member
3 years ago

How to set up a connection between SQL and Test complete using C sharp script?

I am trying to use the below code in Test complete tool to read the data/table from SQL server. But I am unable to get the connection between the two. I guess I need to set up a DSN link but not sure how to do that either. Since I am very new to SQL server so need some guidance.

 


// Access via analogues of Delphi ADO objects

function TestSQL_ADO()
{
var aTable, S, i;
// Creates a table
//aTable = ADO["CreateADOTable"]();
// Specifies the database name
aTable["ConnectionString"] = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=NameOfMyDSN";
// Specifies the table name
aTable["TableName"] = "Tables";
// Opens the table
aTable["Open"]();
aTable["First"]();
// Retrieves field names
S = "";
for (i = 0; i < aTable["FieldCount"]; i++)
S = S + aTable["Field"](i)["FieldName"] + "\t";
S = S + "\r\n";
// Scans dataset records
while (! aTable["EOF"])
{
for (i = 0; i < aTable["FieldCount"]; i++)
S = S + aTable["Field"](i)["AsString"] + "\t";
S = S + "\r\n";
aTable["Next"]();
}
// Outputs results
Log["Message"]("Tables", S);
// Closes the table
aTable["Close"]();
}

No RepliesBe the first to reply