Just wondering if SqlConnection will be dipodized / closed when this method is executed? Or do I need to explicitly call the close method at the end?
using (SqlCommand cmd = new SqlCommand(sql, GetConnection())) { SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { } } SqlConnection GetConnetion() { return new SqlConnection("connectionstring"); }
I know I can do something like this:
SqlConnection conn = GetConnetion(); SqlCommand cmd =new SqlCommand(sql, conn);
But just curious how the used block will work in this case. Greetings
Anton P
source share