1. What is the error that is thrown on that line of code?
2. With reference to the link MSDN Link below
MSDN SqlCommand.ExecuteReader Method ()
- You could catch all the different types of exceptions (Pokemon handling)
- This is not recommended if you are not going to do anything about the specific errors.
3. Replace
SqlDataReader rs = cmd.ExecuteReader();
with the following
try
{
SqlDataReader rs = cmd.ExecuteReader();
}
catch (InvalidCastException exception)
{
Debug.WriteLine(exception.Message)
}
catch (SqlException exception)
{
Debug.WriteLine(exception.Message)
}
catch (InvalidOperationException exception)
{
Debug.WriteLine(exception.Message)
}
catch (IOException exception)
{
Debug.WriteLine(exception.Message)
}
catch (Exception exception)
{
Debug.WriteLine(exception.Message)
}
4. Add this to the top of the page
using System.Diagnostics;
This will assist with determining what the exception type is and the error.