On Oct 24, 2006, at 8:35 AM, Michael Bayer wrote:
>
> the SQLAlchemy engine corresponds to a single connection URL. if you
> want to close all connections, call dispose() on the engine.
>
> if you want an engine that remains, but does not "pool" the
> connections and literally closes the connection for each close()
> operation, you can try creating a "fake" connection pool, (this could
> be added to the dist):
>
> import sqlalchemy.pool as pool
> class FakePool(pool.Pool):
> def status(self):
> return "FakePool"
>
> def do_return_conn(self, conn):
> conn.close()
>
> def do_return_invalid(self, conn):
> pass
>
> def do_get(self):
> return self.create_connection()
>
> then create the engine:
>
> e = create_engine(url, poolclass=FakePool)
I too have a case where I'd like to close all connections to a given
database. But in my case I'm just temporarily closing connections
while performing admin tasks on the database. When the admin tasks
have completed the connection pool should simply reconnect to the
database and pool the connections normally (I can guarantee that the
app will not try to create new connections while the admin tasks are
running). It seems like the right approach here would be to have a
method that would close all open connections. After that, the pool
would simply open and pool new connections as needed. It even looks
like there is already a method that does that:
QueuePool.dispose() # closes all open connections
The problem is getting to the pool instance to call that method...
metadata.engine.connection_provider._pool.dispose()
I have to access a private member to do that--ouch! Maybe the engine
and/or the metadata could have a method something like this:
engine.close_all_connections()
I wouldn't call it "dispose()" since that sounds permanent, like it
might not allow any new connections after the method is invoked. What
do you think?
~ Daniel
>
>
> On Oct 24, 2006, at 8:07 AM, Gary D wrote:
>
>>
>> In my utility using SA against MS SQLServer I'm trying to properly
>> disconnect from a database and connect to another one. I can't
>> seem to
>> find an easy way to do this. Closing a connection just puts that
>> connection back into the pool. I don;t want to do that.
>>
>> I have many (100+) databases on several SQLServer servers that I want
>> to connect, do stuff, disconnect and move onto the next one. I don't
>> want to accumulate hundreds of connections until the program quits.
>>
>> Currently I'm doing this to connect to a database:
>>
>> db = create_engine('mssql://sa:[EMAIL PROTECTED]/she9832')
>> connection = db.connect()
>> metadata.connect(db)
>> session = create_session(bind_to=db)
>>
>> where metadata is a DynamicMetaData instance.
>>
>> What's the recommended way of doing this sort of thing?
>>
>>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sqlalchemy
-~----------~----~----~----~------~----~------~--~---