how to keep one connection between two aspx page calls

L

Larry

Hi



I have asp.net programs. I used a very simple data transfer method by using
URLs



¡°First.aspx¡± contents a line to send data to the ¡°second.aspx¡± page, for
example: http://server/path/seond.apsx?data=mydata



There is a customer setting refresh rate in ¡°First.aspx¡± page.

So, if customer set refresh rate to 6 sec (mydata could be different each
time), there are more then 10 different calls (connections) to
¡°second.aspx¡± from the same ¡°first.aspx¡± page in one minute. This gave
me Error 403.9. (too many connections)



Is anyway I can keep the one connetions all the time between the two pages?



thanks
 
G

Guest

L

Larry

will it be ok if I use the "connection lifetime" in my connection string?

"Server=mypc;Database=mydata;User ID=sa;Password=ps;Trusted_Connection=True;
Connection Lifetime=5"

disconnect it after 6 sec.
thanks
 
G

Guest

Hello Larry,

You can certainly experiment with the Connection Lifetime values if you find
that it makes a difference. But, are you still getting the "too many
connections" error if you close the connection object directly after the
retrieval of the data is done in every page?
 
J

jasonkester

As I mentioned below, you are not disposing of your connection when you
are finished with it. If you wrap it in a using block, it will be
marked for garbage collection immediately after you close it.

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/
 
U

Usenet User

As I mentioned below, you are not disposing of your connection when you
are finished with it. If you wrap it in a using block, it will be
marked for garbage collection immediately after you close it.

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/


Not quite so. If your object uses a connection, simply disposing of it
is not the right way to close a connection. Instead, the connection
should be explicitly closed in the Dispose method of the IDisposable
interface:

public class MyWarrer : IDisposable
{
private SqlConnection _conn = null;
private bool _connIsMine = false;

// Constructor
public MyWrapper( SqlConnection conn )
{
if( conn != null )
{
this._conn = conn;
}
else
{
this._conn = new SqlConnection();
this._connIsMine = true;
}
}

...

// IDisposable implementation - clean up
public void Dispose()
{
if( this._connIsMine
&& this._conn != null )
{
this._conn.Close();
this._connIsMine = false;
}
}
}

Then elsewhere you can use something like this:

using( MyWrapper wrapper = new MyWrapper( null ) )
{
// do you stuff
}

The above code allows you to use multiple wrappers and share the same
connection between them w/o risking leaving it open after the work is
done. The wrapper where the connection is created will be the one who
closes it as well. Normally, this the outermost wrapper in the calling
chain, assuming you are using wrappers from within each other.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top