Click here to Skip to main content
14,664,450 members
Rate this:
Please Sign up or sign in to vote.

I am working on Desktop application. I am running a query to fetch data from database. When there are too many data rows, then it executes that query for the first time. on executing it for the second time, it gives me an error
The underlying connection was closed: An unexpected error occurred on a receive.

How can I execute that query more than once? I am using web service.

Thanks in advance.

Updated 6-Apr-12 0:05am
ZurdoDev 6-Apr-12 7:59am
You need to share your code so we can help.
Shahin Khorshidnia 6-Apr-12 9:10am
And the code?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Protected Overrides Function GetWebRequest(uri As Uri) As WebRequest
	Dim myWebRequest As HttpWebRequest = DirectCast(MyBase.GetWebRequest(uri), HttpWebRequest)
	myWebRequest.KeepAlive = False
	Return myWebRequest 
End Function

And Look at this:;EN-US;915599[^]
MacParekh 7-Apr-12 2:52am
Hi Shahin

Thanks for your reply.
Actually my application is desktop so there is no web.config or Http request.
there is app.config in my application.

My query returns 50k+ rows. whenever there is less count of rows application is working fine. but when large amount of rows comes at that time this type of error occurs.

Any Other solution

Thank You
Shahin Khorshidnia 7-Apr-12 4:53am
Does your application is accessing directly to database?
You told that you where using web service. So you must override GetWebRequest in your webservice.
Look at this please:
MacParekh 7-Apr-12 6:12am
Dear Shalin,
I have faced same problem in web application. I already solved it as u told. I have updated webconfig. and updated maxhttprequest value.

Now Problem is that.. I am using web service in desktop as class file...It is installed in local machine. So there is no http connection occur.

Shahin Khorshidnia 7-Apr-12 8:47am
So, we must see the code as ryanb31 and I said before!

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100