A
Ashish
Hi,
I am getting following error in production for a background process:
Failed to fill Order Data Set :
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.
Object reference not set to an instance of an object.
I have tried my hard to find out the solution. I know it happens when
connections are not closed, but the connection seems to be getting
closed (please see the code snippet below).
I have tried to analyze using
1. sp_who or sp_who2
2. Perf Counters
but i am not getting any clue..
and the process is breaking in this method call only.
Its really frustating that I have to analyze this process and whenever
it breaks i have to rerun it manually. I have read somewhere that using
Data Adapter Fill or Update may result in Connection Leaks..
Please look into the code snippet below:
Thanks
Ashish
Code Snippet:
Entities.Orders.ShippingAddressDataSet resultsDS = new
Entities.Orders.ShippingAddressDataSet();
SqlConnection dbConnection = new SqlConnection(ConnectionString);
try
{
dbConnection.Open();
System.Data.SqlClient.SqlCommand cmdShippingAddressSelect = new
System.Data.SqlClient.SqlCommand();
//
// cmdShippingAddressSelect
//
cmdShippingAddressSelect.CommandType =
System.Data.CommandType.StoredProcedure;
cmdShippingAddressSelect.CommandText = "AddressReadByAddressID";
cmdShippingAddressSelect.Connection = dbConnection;
cmdShippingAddressSelect.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@AddressID",
System.Data.SqlDbType.Int, 4));
cmdShippingAddressSelect.Parameters["@AddressID"].Value = addressID;
System.Data.SqlClient.SqlDataAdapter shippingAddressDataAdapter = new
System.Data.SqlClient.SqlDataAdapter();
shippingAddressDataAdapter.SelectCommand = cmdShippingAddressSelect;
shippingAddressDataAdapter.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[]
{new System.Data.Common.DataTableMapping("Table",
"ShippingAddressList",
new System.Data.Common.DataColumnMapping[]
{
new System.Data.Common.DataColumnMapping("UserID", "UserID"),
new System.Data.Common.DataColumnMapping("addresstypeid",
"addresstypeid"),
new System.Data.Common.DataColumnMapping("inactive", "inactive"),
new System.Data.Common.DataColumnMapping("description",
"description"),
new System.Data.Common.DataColumnMapping("addressid", "addressid"),
new System.Data.Common.DataColumnMapping("address1", "address1"),
new System.Data.Common.DataColumnMapping("address2", "address2"),
new System.Data.Common.DataColumnMapping("address3", "address3"),
new System.Data.Common.DataColumnMapping("city", "city"),
new System.Data.Common.DataColumnMapping("state", "state"),
new System.Data.Common.DataColumnMapping("zip", "zip"),
new System.Data.Common.DataColumnMapping("country", "country"),
new System.Data.Common.DataColumnMapping("metroarea", "metroarea"),
new System.Data.Common.DataColumnMapping("datecreated",
"datecreated"),
new System.Data.Common.DataColumnMapping("usercreated",
"usercreated"),
new System.Data.Common.DataColumnMapping("dateupdated",
"dateupdated"),
new System.Data.Common.DataColumnMapping("userupdated",
"userupdated"),
new System.Data.Common.DataColumnMapping("phone", "phone"),
new System.Data.Common.DataColumnMapping("fax", "fax"),
new System.Data.Common.DataColumnMapping("recipientname",
"recipientname"),
new System.Data.Common.DataColumnMapping("IsDavValid", "IsDavValid")
})
});
shippingAddressDataAdapter.Fill(resultsDS);
}
catch (Exception exp)
{
throw new DBErrorException("Problem with AddressReadByAddressID ID: '"
+ addressID.ToString() + "'", exp);
}
finally
{
if(dbConnection != null)
{
if(dbConnection.State != System.Data.ConnectionState.Closed)
{
dbConnection.Close();
}
dbConnection.Dispose();
}
}
return resultsDS;
I am getting following error in production for a background process:
Failed to fill Order Data Set :
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.
Object reference not set to an instance of an object.
I have tried my hard to find out the solution. I know it happens when
connections are not closed, but the connection seems to be getting
closed (please see the code snippet below).
I have tried to analyze using
1. sp_who or sp_who2
2. Perf Counters
but i am not getting any clue..
and the process is breaking in this method call only.
Its really frustating that I have to analyze this process and whenever
it breaks i have to rerun it manually. I have read somewhere that using
Data Adapter Fill or Update may result in Connection Leaks..
Please look into the code snippet below:
Thanks
Ashish
Code Snippet:
Entities.Orders.ShippingAddressDataSet resultsDS = new
Entities.Orders.ShippingAddressDataSet();
SqlConnection dbConnection = new SqlConnection(ConnectionString);
try
{
dbConnection.Open();
System.Data.SqlClient.SqlCommand cmdShippingAddressSelect = new
System.Data.SqlClient.SqlCommand();
//
// cmdShippingAddressSelect
//
cmdShippingAddressSelect.CommandType =
System.Data.CommandType.StoredProcedure;
cmdShippingAddressSelect.CommandText = "AddressReadByAddressID";
cmdShippingAddressSelect.Connection = dbConnection;
cmdShippingAddressSelect.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@AddressID",
System.Data.SqlDbType.Int, 4));
cmdShippingAddressSelect.Parameters["@AddressID"].Value = addressID;
System.Data.SqlClient.SqlDataAdapter shippingAddressDataAdapter = new
System.Data.SqlClient.SqlDataAdapter();
shippingAddressDataAdapter.SelectCommand = cmdShippingAddressSelect;
shippingAddressDataAdapter.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[]
{new System.Data.Common.DataTableMapping("Table",
"ShippingAddressList",
new System.Data.Common.DataColumnMapping[]
{
new System.Data.Common.DataColumnMapping("UserID", "UserID"),
new System.Data.Common.DataColumnMapping("addresstypeid",
"addresstypeid"),
new System.Data.Common.DataColumnMapping("inactive", "inactive"),
new System.Data.Common.DataColumnMapping("description",
"description"),
new System.Data.Common.DataColumnMapping("addressid", "addressid"),
new System.Data.Common.DataColumnMapping("address1", "address1"),
new System.Data.Common.DataColumnMapping("address2", "address2"),
new System.Data.Common.DataColumnMapping("address3", "address3"),
new System.Data.Common.DataColumnMapping("city", "city"),
new System.Data.Common.DataColumnMapping("state", "state"),
new System.Data.Common.DataColumnMapping("zip", "zip"),
new System.Data.Common.DataColumnMapping("country", "country"),
new System.Data.Common.DataColumnMapping("metroarea", "metroarea"),
new System.Data.Common.DataColumnMapping("datecreated",
"datecreated"),
new System.Data.Common.DataColumnMapping("usercreated",
"usercreated"),
new System.Data.Common.DataColumnMapping("dateupdated",
"dateupdated"),
new System.Data.Common.DataColumnMapping("userupdated",
"userupdated"),
new System.Data.Common.DataColumnMapping("phone", "phone"),
new System.Data.Common.DataColumnMapping("fax", "fax"),
new System.Data.Common.DataColumnMapping("recipientname",
"recipientname"),
new System.Data.Common.DataColumnMapping("IsDavValid", "IsDavValid")
})
});
shippingAddressDataAdapter.Fill(resultsDS);
}
catch (Exception exp)
{
throw new DBErrorException("Problem with AddressReadByAddressID ID: '"
+ addressID.ToString() + "'", exp);
}
finally
{
if(dbConnection != null)
{
if(dbConnection.State != System.Data.ConnectionState.Closed)
{
dbConnection.Close();
}
dbConnection.Dispose();
}
}
return resultsDS;