Re: Persist a database connection across postbacks



Godwin Burby wrote:
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

.



Relevant Pages

  • Re: ADO Connection Timeout
    ... so what happens when a connection failure forces one station to revert ... to a local database? ... Further, you *will* have contention issues, Jet does not support record ... to the central server, but you are willing to live with periods where it ...
    (microsoft.public.data.ado)
  • Re: ADO Connection Timeout
    ... When the first test is run, the results are stored in the central database. ... to the central server, but you are willing to live with periods where it ... i.e. a local database or even a text file. ... to function until the connection can be restored to the server. ...
    (microsoft.public.data.ado)
  • Re: ADO Connection Timeout
    ... to the central server, but you are willing to live with periods where it ... i.e. a local database or even a text file. ... to function until the connection can be restored to the server. ...
    (microsoft.public.data.ado)
  • Re: Communicating over the internet
    ... > That way you provide one manner in which to open the database, ... > can keep the connection open and then when someone wants to ... > server as the database and the soap dll connecting with a TCP socket. ... The name of the running program might help. ...
    (microsoft.public.vb.general.discussion)
  • Re: ADO Connection Timeout
    ... much rather write stored procedures and use server side cursors. ... local database, it is vital that I get the information to a central server. ... Once the connection is restored, ...
    (microsoft.public.data.ado)