Hi,
I am using sqlalchemy version 0.7.6 on Win 7. I am using sqlalchemy to 
execute raw SQL queries in parallel. Here is how I do it:


eng = get_engine() #Threadsafe method to get engine
raw_con = eng.connect().connection.connection
raw_con.autocommit= True
crsr = raw_con.cursor()
res = crsr.execute (qry, *multiparams) #multiparams is empty in my case
raw_con.autocommit= False
If it is a select query:
    res_fetched = res.fetchall()
res.close()

Sometimes, I get *Error: ('HY000', '[HY000] [Microsoft][ODBC SQL Server 
Driver]Connection is busy with results for another hstmt (0) 
(SQLExecDirectW)')*
Looking at the logs I can see that two queries were indeed running 
together- one was a bulk insert (an update query) and another was a select 
query. 

If it is a select query:
    res_fetched = res.fetchall()

is just a convenient\brief way of writing it here. I actually have separate 
select and update functions, that call the 'execute' function. The select 
function will then do a fetchall, but the update function will not.


>From the docs 
>here<http://docs.sqlalchemy.org/en/rel_0_7/core/connections.html#sqlalchemy.engine.base.Engine.connect>
:

The 
Connection<http://docs.sqlalchemy.org/en/rel_0_7/core/connections.html#sqlalchemy.engine.base.Connection>
 object 
is a facade that uses a DBAPI connection internally in order to communicate 
with the database. This connection is procured from the connection-holding
Pool<http://docs.sqlalchemy.org/en/rel_0_7/core/pooling.html#sqlalchemy.pool.Pool>
 referenced 
by this 
Engine<http://docs.sqlalchemy.org/en/rel_0_7/core/connections.html#sqlalchemy.engine.base.Engine>.
 
When the 
close()<http://docs.sqlalchemy.org/en/rel_0_7/core/connections.html#sqlalchemy.engine.base.Connection.close>
 method 
of the 
Connection<http://docs.sqlalchemy.org/en/rel_0_7/core/connections.html#sqlalchemy.engine.base.Connection>
 object 
is called, the underlying DBAPI connection is then returned to the 
connection pool, where it may be used again in a subsequent call to 
connect()<http://docs.sqlalchemy.org/en/rel_0_7/core/connections.html#sqlalchemy.engine.base.Engine.connect>
.

If I understand the above correctly, and assuming that the engine connect 
function is thread safe, the two queries running simultaneously should be 
running with different raw_con objects. 
Not sure why I am running into this error. 

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to