DatStat Illume 4.5 SDK Class Reference

HookContext.ExecSQLWithResults Method 

Returns a SqlDataReader resulting from the execution of the given SQL query statement sqlStatement.

public SqlDataReader ExecSQLWithResults(
   String sqlStatement
);

Parameters

sqlStatement
The SQL query statement to execute.

Return Value

A SqlDataReader object for reading the results of the SQL query.

Remarks

At times there may be a need to perform queries against the DatStat Illume schema views provided with the DatStat Illume SDK or against other schema that exist in the same SQL Server as DatStat Illume.

This method provides the ability to perform SQL Select queries against the SQL Server hosting DatStat Illume. The added benefit of this method is that it will use the existing DatStat Illume Collector connection pool alleviating the need for the developer to get a connection. The SqlDataReader returned by this method should be closed by the developer. However, stale SqlDataReaders will always be closed on subsequent calls to this method. The important side-effect of this is that only a single SqlDataReader provided by a call to this method can be used at a time. For example the following code would not work:

SqlDataReader reader1 = ctx.ExecSQLWithResults(“select fname, lname from table1”);
SqlDataReader reader2 = ctx.ExecSQLWithResults(“select age from table1”);
while(reader1.Read()){
    ...
}
The second call to ExecSQLWithResults will result in the closing of the ‘reader1’ SqlDataReader and the ‘while’ loop will never execute.

If there are errors during the execution of the provided SQL Statement, this call will throw an exception. It will be up to the hook developer to catch these exceptions and it is very important that this is done or the survey will stop running resulting in your survey participant getting presented with an error page with very limited information.

See Also

HookContext Class | DatStat.Collector Namespace | ExecSQLCommand | SqlDataReader