Can it be owing to no record returned?
The other way round. No rows are being returned, because your query/batch run into an error.
You need to capture the error message with an exception handler and get the text of the error message.
Here is a simple sample program of how to capture exceptions with SqlDataReader_
using System.Data.SqlClient;
public static class SqlErrorRepro {
private static string sqlBatchText = @"
BEGIN TRY
SELECT name, log(max_length) FROM sys.columns
END TRY
BEGIN CATCH
; THROW
END CATCH";
private static string connString =
@"Data Source=.;Integrated Security=SSPI;Database=tempdb";
public static void Main() {
try {
using (SqlConnection cn = new SqlConnection(connString))
using (SqlCommand cmd = new SqlCommand(sqlBatchText, cn)) {
int rowCount = 0;
cn.Open();
using (SqlDataReader reader = cmd.ExecuteReader()) {
while(reader.Read()) { ++rowCount; };
while(reader.NextResult());
}
System.Console.WriteLine("{0} rows read", rowCount);
}
}
catch (System.Exception ex){
System.Console.WriteLine("ERROR: " + ex.Message);
}
}
}