Persist a database connection across postbacks

G

Godwin Burby

Hi All,
I'm a new comer to web development as well as asp.net. So when
i fired up my first database driven page, i knew i had a problem of not
having a persistent database connection across postbacks. I tried to
piggyback the connection object to application object and it didn't
work. Well i do know that you ASP.net experts have a default way of
handling this scenario. Please enlighten me.
 
D

Damien

Godwin said:
Hi All,
I'm a new comer to web development as well as asp.net. So when
i fired up my first database driven page, i knew i had a problem of not
having a persistent database connection across postbacks. I tried to
piggyback the connection object to application object and it didn't
work. Well i do know that you ASP.net experts have a default way of
handling this scenario. Please enlighten me.

Just my two-penneth, and may not be the answer you're looking for:

Create a function that creates/sets up your connection. Whenever you
need to interact with the database, call this function, do your data
work, and close the connection. Let the .NET framework worry about
connections and connection pooling.

This may at first sound counterintuitive, and up until a few months
ago, I was going along the route of "create one connection, share it
around, and keep it open". I had a stubborn application that was taking
four hours to perform some processing (admittedly, I was abusing
ASP.NET quite considerably to get this working). I switched around to
opening connections when I needed them, doing the db work, and closing
the connection. The same process then started taking less than ten
minutes.

The Open/Use/Close approach should definitely scale better than either
a) one connection for the whole application, or b) one connection per
session. (a) has problems because you have to do a lot of locking
around every db interaction to make sure no-one else is using it. (b)
can fail if the user opens a second browser window and fires off two db
related tasks simultaneously.

Damien
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top