1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

making an open connection persistant in asp.net

Discussion in 'C#' started by spyrit, May 30, 2006.

  1. #1
    Hy there guys, i have a proble, hope you can help me.
    I have a webpage asp.net, in the aspx.cs i make a mysql connexion and i oppen it. the connexion is to a database that is located on a remote machine running linux. The problem is that the connexion.Open() is taking too much time, aroun 25 seconds each time. And i open it and close it in a few controls i use on the page, nd each time i have to wait a long time. The question is: is there a way to make the connexion persistant? I mean to open it only once at the beginning and close it at the end?? Or is there a way to speed up the open proccess so it won't take this much time??
    Thx for your help.
    SEMrush
     
    spyrit, May 30, 2006 IP
    SEMrush
  2. hcole

    hcole Peon

    Messages:
    21
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have you tried putting the code to open the connection in the Session_Start event of the global.asax page?
     
    hcole, Jul 1, 2006 IP
  3. benjymouse

    benjymouse Peon

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You should never hold on to a database connection. ASP.NET supports connection pooling. You should check the documentation for how to enable connection pooling, but it really should be enabled by default.

    To get the best of connection pooling you should open late and close early. Even multiple open/close on a single page is ok, as with pooling the connections are not really closed, but merely returned to a pool, from which it is taken the next time someone "opens" a connection.

    Persistíng the connection in application scope is not a good idea. Concurrent requests will use it simultaneously, resulting in sharing exceptions.

    To connect to mySQL it is best to use a native .NET provider. The mySQL hime page links to a couple of alternatives (one OS another commercial). These should support connection pooling out of the box.
     
    benjymouse, Jul 3, 2006 IP
  4. DanInManchester

    DanInManchester Active Member

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    opening and closing connections should be rapid and benjymouse is absolutely right.

    you could potentially speed things up by caching your pages / data if that is appplicable to your scenario but it sounds like you have an underlying problem.

    I think the issue is with your database server response time.
    Is the server over burdened or are the queries large and complex?
    Maybe the issue is with your network?
     
    DanInManchester, Jul 5, 2006 IP
  5. spyrit

    spyrit Well-Known Member

    Messages:
    1,788
    Likes Received:
    94
    Best Answers:
    0
    Trophy Points:
    150
    #5
    thx guys...yeah it was something about the network, a friend of made made it work....thx again for your help
     
    spyrit, Jul 5, 2006 IP