Hi!
Can I avoid the open DataReader exception ("There is already an open DataReader associated with this Command which must be closed first.") when using constructs like this one?
public void FirstMethod()
{
using (var command = connection.CreateCommand())
{
command.CommandText = "...";
using (var reader = command.ExecuteReader())
{
// do something with the data
SecondMethod();
}
}
}
public void SecondMethod()
{
using (var command = connection.CreateCommand())
{
command.CommandText = "...";
using (var reader = command.ExecuteReader()) // Exception
{
}
}
}
Best Regards