What I'm trying to do is to call a stored proc using ado.net and get its result. I have tried to execute the stored proc in ssms and its working fine.
But when I tried to run it through the code, the result is empty, so I tried to debug and here is my issue.
Below is my code which I'm trying to debug.
using (SqlConnection sql = new SqlConnection(_connString))
{
using (SqlCommand cmd = new SqlCommand("GetDdmhData", sql))
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@requestDate", dateReport.Value.Date.ToString("yyyy-MM-dd")));
await sql.OpenAsync();
using (var reader = await cmd.ExecuteReaderAsync())
{
while (await reader.ReadAsync())
{
var test = "";
}
}
}
}
I have kindda weird issue. I placed my breakpoint at the below statement
while (await reader.ReadAsync())
Once my breakpoint is hit, I i did a QuickWatch on the 'reader' value and it returns me some rows.
Then I close the QuickWatch window, and straight away open back the Quickwatch window on the 'reader', and suddenly, the result is empty.
Can someone explain to me why is that happening and how to resolve this issue?