Error :Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have...

Hi ,
In my Asp.net web application when i try to access a web-service after sending my credentials i get the exception
"
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. "


But when  i try to access the same web service url on my localhost , while debugging my local application in VS , it runs perfectly and  provides me with xml response.
I am not able to fix the problem   I have tried following things :

1) Increased the connection timeout on my web server.
2) Set the pool size to maximum .

But still it persists.

Please help , I am confused about the location of problem , my web server or the server from where i am accessing the web service .

vikasbapatAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
shrinivasmwCommented:
See increasing connection pool size only will not help. Check if you are opening connection explicitly need to close it as well.

Check in code whether you are closing or not the connection object.

Please let me know whether this works or not.

Shriniwas Wani
0
 
RameshSCommented:
It seems that your web service is trying to access an SQl Server database.
Check whether SqlConnection object is properly closed using SqlConnection.Close() method.
Also check in the SQL server instance, how many connections are open from web service connection string using sp_who procedure.
You can also use the performance monitor console to check the connection pool of the SQL Server instance.  Try the following link.
http://msdn.microsoft.com/en-us/library/8xx3tyca(VS.71).aspx

0
 
jtdebeerCommented:
Also see this article if you are closing connections properly.
http://www.15seconds.com/Issue/040830.htm
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
vikasbapatAuthor Commented:
                        shrinivasmw , Thanks for ur answer .
Yes i am closing the connection .Please see code below thats causing the error.

 string projecturl = "www.mywebservice.com/userid/password"
  HttpWebRequest req = (HttpWebRequest)WebRequest.Create(projecturl);
        req.Method = "GET";
        req.ContentType = ".xml";
        HttpWebResponse res = (HttpWebResponse)req.GetResponse();
        StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
        string backstr = sr.ReadToEnd();
       
 sr.Close();//                     This is where i close connection
        res.Close();//


0
 
shrinivasmwCommented:
Hi Vikas,

You must call the Close method to close the stream and release the connection. Failure to do so may cause your application to run out of connections.

So modify ur code :
       res.Close();//  close stream obj first then
 sr.Close();//                     This is where i close connection

I belive this will help. Please let me know if it works or not.

Shriniwas Wani
0
 
vikasbapatAuthor Commented:
shrinivas,

I modified my code as per you said . But its still same ..after 3-4 qattempts it cpnnects to web service .

My question however is : Why it throws this exception when i try to access a 3rd party web service & not to my own database ???
Thanks for ur help .. I really appreciate it
0
 
shrinivasmwCommented:
Hi Vikas,
This is all memory/connection object related issue.

I will suggest you to go through this article on MSDN.
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.getresponse.aspx

It will help. Let me know if it works.
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.