How the Connection be closed

Jun 18, 2014 at 12:54 PM
Edited Jun 18, 2014 at 12:55 PM
This is my code:

using (var cmd = _db.GetSqlStringCommand("Delete from tb1 where id=@Id ))
            _db.AddInParameter(cmd, "@Id", DbType.Int64, Id);
I sometimes get the following error message.
The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.

I not sure if the error is cause by my code above. But I don't see any Close method on connection object is invoked.

Can anyone help me understand how the connection object is managed in SqlDatabase?
Jun 20, 2014 at 4:09 AM
Enterprise Library manages the connection for you so you don't need to close the connection. ExecuteNonQuery opens a connection and then disposes the connection. You can see the code here: .

Randy Levy
Enterprise Library support engineer
Support How-to