The problem I'm facing is that since from main method I already have SqlDataReader being hold to read and so I cant update now. Any work around for me?
That's only a problem because you're sharing the connection (myConnection
). Don't do that. Create a new SqlConnection
every time you want to perform a database operation, and let the connection pool infrastructure handle making it efficient. Also, use using
statements for database-related resources:
using (var connection = new SqlConnection(...))
{
using (var command = new SqlCommand(...))
{
using (var reader = command.ExecuteReader(...))
{
...
}
}
}