How the Connection be closed

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

using (var cmd = _db.GetSqlStringCommand("Delete from tb1 where id=@Id ))
        {
            _db.AddInParameter(cmd, "@Id", DbType.Int64, Id);
            _db.ExecuteNonQuery(cmd);
        }
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 5: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: http://daab.codeplex.com/SourceControl/latest#source/Src/Data/Database.cs .

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to