Just wondering, Would the SqlConnection be diposed/closed when this method is done? Or do i have 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);
//Do Something
conn.Close()
cmd.Dispose()
But just curious how the using block will work in this case. Cheers