On 21 Gen, 16:18, Michael Bayer <mike...@zzzcomputing.com> wrote:
> On Jan 21, 2009, at 5:22 AM, Smoke wrote:
> > Hi,
>
> > I'm not a SQLAchemy expert ( just an average user... ). I have an
> > application that's causing me some problems... It's a monitoring
> > application that connects to a MS Sql Server, so it's always on.
> > Sometimes happens that casualy I have a DBAPIError with pyodbc. The
> > error is something like [Microsoft][ODBC Driver Manager] Driver's
> > SQLAllocHandle on SQL_HANDLE_DBC failed .... After the first time I
> > have  this error every other DB operation generates this Error.
> > So.. what I would like to do is completely close ( kill ) che active
> > connection pool and recreate it. My code is somethink like this:
>
> > sa_engine=sa.create_engine(dbUri, echo=False, strategy='threadlocal')
> > sa_Session = sa.orm.scoped_session( sessionmaker(bind=sa_engine,
> > autoflush=False) )
> > metadata = sa.MetaData(sa_engine)
> > sa_session = sa_Session()
>
> > and then:
>
> > sa_session.close()
> > sa_Session.close_all()
> > sa_engine.dispose()
> > del sa_session
> > del sa_Session
> > del sa_engine
>
> > But after executing this Sql Server Profiler tells me that the
> > connection is still opened. The only way is to kill the application.
> > My sqlalchemy.__version__ is 0.4.8
>
> assuming no other connections are checked out, that would close all  
> connections.  its possible the DBAPI is just not able to close the  
> connection fully.   try with a raw pyodbc application to see if this  
> is the case.   Other things to try are to use the NullPool with  
> create_engine() which doesn't pool connections.   Its also extremely  
> unlikely that you should be using "strategy='threadlocal'" unless you  
> are calling begin()/commit() from your Engine directly so you might  
> want to take that out.

So... i've tried raw pyodbc and i keeps che connection alive too if
you just import pyodbc and create a connection instance. To make
pyodbc close the connection is settine pyodbc.pooling = False. The
people from pyodbc told me they will check out this behavior....
Using NullPool open and immediatly close the connection after doing
the sql stuff, so it should be ok. I'll try and check if it doesn't
affect my app behavior.
About threadlocal.. yeap.. my fault! :P
Thanks very much for the answer.

Fabio
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to