473,385 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Static variables in httphandlers/httpmodules


This is what I'm doing:

I'm using Httpmodules and Httphandlers to control access to files (images,
movies, etc.), but have run into quite a problem when several files are being
requested at the same time, from the same client.
To avoid having to push my database connection around to all the methods of
the classes I've build, the connection is stored in a static variable.

When several files are requested from the same client, at the same time, I
get exceptions when accessing the database ("already an open datareader" and
the like), and I've even gotten a datareader with the wrong data in.
When I'm in debug mode it's a big problem, when I'm building a release
build, it's less a problem, but still there. Once the web application is
under stress, my guess is that it will be a major problem.
To solve this problem, I set the IsReuseable boolean on the HttpHandler to
false, but that didn't help anything.

I thought that a static variable would be static per request, and that
setting the IsReuseable boolean would help, but that is not the case??

Am I missing something, or is this normal behaviour? The same problem arises
when I'm using iframes and have a httphandler catching the aspx requests.

It looks like the content of static variables "survive" from one request to
another, can't this be avoided?? And even worse the static seems to be shared
among more than one request at a time.

Does anybody have any experience with this, and any solution to the problem?!?

tia,
Steen

Nov 18 '05 #1
1 2670
Steen Tøttrup wrote:
This is what I'm doing:

I'm using Httpmodules and Httphandlers to control access to files
(images, movies, etc.), but have run into quite a problem when
several files are being requested at the same time, from the same
client.
To avoid having to push my database connection around to all the
methods of the classes I've build, the connection is stored in a
static variable.

When several files are requested from the same client, at the same
time, I get exceptions when accessing the database ("already an open
datareader" and the like), and I've even gotten a datareader with the
wrong data in.
When I'm in debug mode it's a big problem, when I'm building a release
build, it's less a problem, but still there. Once the web application
is under stress, my guess is that it will be a major problem.
To solve this problem, I set the IsReuseable boolean on the
HttpHandler to false, but that didn't help anything.

I thought that a static variable would be static per request, and that
setting the IsReuseable boolean would help, but that is not the case??

Am I missing something, or is this normal behaviour? The same problem
arises when I'm using iframes and have a httphandler catching the
aspx requests.

It looks like the content of static variables "survive" from one
request to another, can't this be avoided?? And even worse the static
seems to be shared among more than one request at a time.

Does anybody have any experience with this, and any solution to the
problem?!?

tia,
Steen


"static" is application-wide, so *everyone* accessing your application
shares the same single static variable.
Asp.net handles connection pooling itself, so don't try your own pooling.
The best way to use connections is to open them as late as possible,
closing them as soon as possible.
Having that connection in a static variable means that all requests
use just a single connection! So instead of gaining performance,
you lose it.
(storing the connection *string* in a static variable is not a problem)

A single connection can have just one open datareader. That's why you
got that error.

Hans Kesting
Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: MWells | last post by:
I'm having an issue getting my HttpHandlers and HttpModules to play together nicely. My HttpHandlers take special document types (defined by extension) and process them specially. I might have...
0
by: tshad | last post by:
I have 2 controls that I need to run that I got of the Web. I have been using ScrollKeeper for awhile and was trying to add FreeTextBox to my site. But for some reason it won't run if ScrollKeeper...
3
by: =?Utf-8?B?UGF0UA==?= | last post by:
We have a site that gets many requests for nonexistent pages, files and folders. We want those requests redirected to the index page. However, for static files (i.e. images and some other...
0
by: =?Utf-8?B?UmF5?= | last post by:
Nearly all examples of writing HttpModules and HttpHandlers create them in new assemblies. We have a lot of our common code in our "Web.Framework" assembly - if we wrote all our modules and...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.