How do i return a table from a sql server query using Testcomplete?
Hi,
i'm trying to return a table from a sql server query. I have the folowing method but when i look at the results that are return i get the error = error: cannot perfom this operation on a closed dataset:
function ReturnSqlQuery(sqlQuery, connectionString)
{
try
{
var query = ADO.CreateADOQuery();
query.ConnectionString = connectionString;
query.SQL = sqlQuery;
query.Open();
var queryResult = query;
return queryResult;
}
finally
{
Log.Message("Closing the connection.");
query.Close();
}
}
The key here is you're writing out all your returned results BEFORE closing the connection. (I drop them into an array rather than the log, but same thing.)
Same deal.
(I use both - query & execute. Mostly query. But I have to use execute to get back number of affected rows for some calls. It's not requrned as a parameter of a RecordSet object for a standard query. Which is annoying.)