Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I am using SqlHelper (Microsoft DAAB) library to perform database operation. But I have to came across 1 issue when I am getting exception with Connection pool that is full.

I have created basic Scenario for this exception
C#
public void method1(parameters)
{
SqlDataReader dr = null;
try{
dr =SqlHelper.ExecuteReader(CommandType,commandText);
if(dr.HasRows)
{
//Almost 7000 Records
while(dr.Read())
{
//Some Operation
Method2();
}
}
}
catch{}
finally
{
if(dr!= null)
dr.Close();
}
}

public void Method2()
{
SqlDataReader dr = null;
try{
dr =SqlHelper.ExecuteReader(CommandType,commandText);
if(dr.HasRows)
{
while(dr.Read())
{
// Only 1 Record
//Perform Some operation
}
}
}
catch{}
finally
{
if(dr!= null)
dr.Close();
}



using Above code my connection pool is full and not allow more connection Currently we allow 100 connection
Posted

1 solution

That's for a reason that there are certain number of maximum connections available. If not, your code would end up consuming even more.

I don't see anything wrong in the code which you have provided here. However, if I make a guess it should be somewhere in your SQLHelper class which probably handles in the connection to SQL Server.

I would ask you check and make sure that the connection to SQL Server is properly closed.

See here how to close a connection:

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.close(v=vs.110).aspx[^]
 
Share this answer
 
Comments
Jigar Sangoi 19-Nov-14 0:42am    
command.ExecuteReader(CommandBehavior.CloseConnection);

we are using this in SqlHelper which closes connection when Data Reader is closed. This working fine with other code but we just get so much data(7000 records) in currently working functionality which gives above exception

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900