Usually I use the pattern described in this question:
That looks like this:
using (var conn = new SqlConnection(lewtanConnStr))
using (var cmd = new SqlCommand(sql, conn))
{
try
{
await conn.OpenAsync();
using(reader = await cmd.ExecuteReaderAsync())
However, on the MSDN/Microsoft website usually only SqlConnection
is wrapped in a using
block. Is it good enough to just dispose SqlConnection
? (Sometimes even SqlConnection
just calls close()
without wrapping it in using
).
The code examples on this article are one instance:
https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand(v=vs.110).aspx