Max pool connection error while using enterprise library 4.1

Topics: Data Access Application Block
Jul 2, 2015 at 1:12 PM
Hi

I am using below code to connect with database using enterprise library 4.1. Can this lead to connection leak as we are getting this error "Timeout expired. 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"

private static int InsertActivityID(string activityID)
    {
        Database db = DatabaseFactory.CreateDatabase(DBInstanceName);
        int trackingID = 0;
        DbCommand dbcw = null;
        try
        {
    dbcw = db.GetStoredProcCommand(spInsertActivityID);
            SqlParameter InsActId = new SqlParameter("@ActivityID", activityID);
            InsActId.DbType = DbType.String;

            SqlParameter InsTrackId = new SqlParameter();
            InsTrackId.ParameterName = "@TrackingID";
            InsTrackId.DbType = DbType.Int64;
            InsTrackId.Size = 16;
            InsTrackId.Direction = ParameterDirection.Output;

            dbcw.Parameters.Add(InsActId);
            dbcw.Parameters.Add(InsTrackId);

            dbcw.Connection = db.CreateConnection();
            dbcw.Connection.Open();
            dbcw.ExecuteNonQuery();

           if (!string.IsNullOrEmpty(InsTrackId.Value.ToString()))
            trackingID = int.Parse(InsTrackId.Value.ToString());



        }
        catch (Exception ex)
        {
            ExceptionHelper.LogException("EBAM_1001", "", "", "ActivityID : " + activityID + ". Error occurred in InsertActivityID BAM API method - " + ex.Message, "BAMAPI - InsertActivityID method", "BAM E2E Tracking", Severity.Error, ExceptionType.System);

        }
        finally
        {
            dbcw.Connection.Close();

        }

        return trackingID;  

    }