On May 9, 2014, at 4:59 PM, Sylvester Steele <[email protected]> wrote:

> 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:
> 
> The 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-holdingPool referenced by this Engine. When the close() method of 
> the 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().
> 
> 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. 

the code here isn't really showing me the nature of the two separate 
connections.   They will be different unless you're using "threadlocal" on the 
engine or pool and both are in the same thread.  A simple comparison of the 
"raw" DBAPI connections to see if they are different objects will suffice (make 
sure you're on the ultimate DBAPI connection though, not the "fairy" object).   
However note that Microsoft ODBC drivers also feature connection pooling, so 
you'd need to turn it off at the ODBC configuration level as well.

-- 
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