using (IDbConnection dbConn = new System.Data.SqlClient.SqlConnection(ConnectionString))
{
dbConn.Open();
...
return result;
}
- Will the dbConn.Open() inside the using will use a different connection pool?
- If the question number 1 is true and if the code reaches the return, will this code leaves 2 open connection hanging?
It will create a new connection which will then be disposed of when the using block has reached the end. It's a good idea to close you connection when you no longer need it, if you have more going on in the using block but the using block will handle that.
When the code reaches the return, it exits out of the using statement so it then does the disposing. It's not like it returns and doesn't finish in case thats what you are asking. The dispose is called as soon as the execution leaves that scope. Even if you get an exception the Dispose will be called.
A using block gets compiled into a try catch finally block and the finally is always executed and the finally contains the Dispose