Open and Close a database connection in a request

Showing 1-7 of 7 messages
Open and Close a database connection in a request ProfessionalIT 9/19/12 12:54 PM
How to implement this ?

When I init the request I need open a connection with the database (and execute a query for example) and in the end of the request I need close the database connection. 

Another question is: How I know that a database connection is open ?

ps: sorry by my 'dummie questions' and by my terrible english !.





   
Re: Open and Close a database connection in a request ProfessionalIT 9/19/12 1:54 PM
Well,

   I'm trying implement this then in my code.py I have this code:

from model import setDB, unsetDB

def db_handler(handler):
    setDB()
    result=handler()
    unsetDB()
    return result

webapp = web.application(urls, globals())
webapp.add_processor(db_handler)


im my model.py I have this code:

db = web.database(dbn=DBN, host=HOST, db=DB, user=USER, pw=PWD)

def unsetDB():
    print '>>>>>>>>> in the unset <<<<<<<<<<<'
    db = None
    print str(db)

def setDB():
    print '>>>>>>>>> in th SET <<<<<<<<<<<'
    unsetDB()
    db = web.database(dbn=DBN, host=HOST, db=DB, user=USER, pw=PWD)
    print str(db)

but when I look in my system process monitor I still have a opened connection with database

any idea ?
Re: Open and Close a database connection in a request Francois Dion 9/19/12 5:46 PM


On Wednesday, September 19, 2012 3:54:12 PM UTC-4, ProfessionalIT wrote:
How to implement this ?

When I init the request I need open a connection with the database (and execute a query for example) and in the end of the request I need close the database connection. 


Por que fechar a conexão?

Normally, for performance, you want to open the connection as soon as you get a chance and _keep_ it open. What problem are you trying to solve?

Tchau,
Francois

--
Francois Dion
http://solarisdesktop.blogspot.com
Re: Open and Close a database connection in a request ProfessionalIT 9/19/12 6:51 PM
Por que fechar a conexão?

Normally, for performance, you want to open the connection as soon as you get a chance and _keep_ it open. What problem are you trying to solve?

Tchau,
Francois

Francois,
   
    Well, I think that when many visitants access the website (where each access is a new browser session and a new database connection correct ? )  this can leave the website slow. 
   
     Actually I still don't know how...I don't understand how the connections works in web.py, for example, I don't know when the connection is closed.

    But, thank you so much for your replay.
    
    Best regards,
    Leandro.

Re: Open and Close a database connection in a request ProfessionalIT 9/21/12 6:04 AM
 Friends,
 
   Any idea ?, tip ? or suggestion ?

  
Re: [webpy] Re: Open and Close a database connection in a request Francois Dion 9/21/12 7:11 AM
Bom dia,

I dont see what the problem is. What database are you using? What kind
of load are you talking about?

Francois



--
Francois Dion
http://solarisdesktop.blogspot.com

On Fri, Sep 21, 2012 at 9:04 AM, ProfessionalIT <lsev...@gmail.com> wrote:
>  Friends,
>
>    Any idea ?, tip ? or suggestion ?
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "web.py" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/webpy/-/WgK-kI1cAEQJ.
>
> To post to this group, send email to we...@googlegroups.com.
> To unsubscribe from this group, send email to
> webpy+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/webpy?hl=en.
Re: [webpy] Re: Open and Close a database connection in a request Tomas Schertel 9/21/12 10:35 AM
Hi Leandro,

Have you monitored your database to see how many connections does it has?
I may be wrong, but I think db connections number aren't related to sessions number.