2
Follows the code:
public ActionResult Index(ViewModel model, string returnUrl)
{
string query = "UPDATE Table SET Status = 'C' WHERE Id = @Num";
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
using (SqlCommand command = new SqlCommand(query, connection))
{
command.Parameters.Add("@Num", SqlDbType.Int).Value = model.Numero;
connection.Open();
command.ExecuteNonQuery();
connection.Close();
}
return RedirectToAction("Page", "Account");
}
I get a warning in the bug lists:
CA2202: The 'Connection' object can be discarded more than once in the method 'Accountcontroller.Index(Viewmodel, string)'. To avoid generating System.Objectdisposedexception, do not call Dispose more than once on an object.
Some solution?