<br><br><div class="gmail_quote">On Tue, Nov 27, 2012 at 4:16 AM, Hynek Schlawack <span dir="ltr">&lt;<a href="mailto:hs@ox.cx" target="_blank">hs@ox.cx</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
I have a really bad time with the combination of a low-volume service  and adbapi.ConnectionPool, pyodbc, FreeTDS and Sybase.<br>
<br>
Basically my connections just time out and fail in weird, generic ways like:<br>
<br>
Error: (&#39;01000&#39;, &#39;[01000] [FreeTDS][SQL Server]Unexpected EOF from the server (20017) (SQLEndTran)&#39;)<br>
<br>
(but in many others too, there is no real pattern)<br></blockquote><div><br>Have you tried enabling reconnects (cp_reconnect=True)? If &quot;select 1&quot; doesn&#39;t work with your database you may also have to pass in custom cp_good_sql.<br>
 <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
In my desperation, I’m employing for-loops for the SQL queries now. :(<br>
<br>
Since there isn’t much traffic (yet) I would like to just make ConnectionPool close the connections and re-open fresh ones, as soon as they are necessary.<br>
<br>
Is there some straight-forward way to do that? Or any better approach I’ve overlooked?<br></blockquote><div><br>Don&#39;t use ConnectionPool at all. Just have a function that does the SQL connect etc usually normal DB-API, and call it with twisted.internet.threads.deferToThread:<br>
<br><div style="margin-left:40px"> <font face="courier new,monospace">def dbTxn(x):<br>    conn = db.connect(...)<br>    cursor = conn.cursor()<br>    cursor.execute()<br>    result = cursor.fetchall()<br>    conn.close()<br>
    return result<br><br>deferredResult = deferToThread(dbtxn, argForX)<br><br></font></div></div></div>-- <br>Itamar Turner-Trauring, Future Foundries LLC<br><a href="http://futurefoundries.com/" target="_blank">http://futurefoundries.com/</a> — Twisted consulting, training and support.<br>
<br>