django-pyodbc
django-pyodbc copied to clipboard
Database Options
Any way to limit the db's connection timeout? It sometimes takes a long couple of seconds to connect to the db and return results.
Would you want the connection to die past a certain limit or do you want to extend the limit?
For the connection to die past a certain limit so the user gets a quicker response.
I think this may be something you need to do on the database server itself (e.g., through SQL Server). @michiya what do you think?
Hi guys,
If you are using FreeTDS, you might be able to specify timeout values with timeout
or connect timeout
settings in freetds.conf. For more details, see:
http://freetds.schemamania.org/userguide/freetdsconf.htm
But if you are using MS ODBC drivers, probably there's no way to specify timeout values at this time because they don't support Connect Timeout
keyword in the connection string.
And now, pyodbc provides the following way to specify timeout values:
-
timeout
kwarg in podbc.connect() this represents SQL_ATTR_LOGIN_TIMEOUT in the ODBC spec. -
timeout
attribute of Connection object this represents SQL_ATTR_CONNECTION_TIMEOUT and SQL_ATTR_QUERY_TIMEOUT in the ODBC spec.
and you can specify timeout values with pyodbc like this:
# connect to the database in 3 seconds
conn = pyodbc.connect(connstr, timeout=3)
# set connection/query timeout to 5 seconds
conn.timeout = 5
So it might be a good idea to slightly modify the backend as above to accept these timeout-related options in the database settings.
Thanks for the info guys!
On Thu, Aug 1, 2013 at 3:21 AM, Michiya Takahashi [email protected]:
Hi guys,
If you are using FreeTDS, you might be able to specify timeout values with timeout or connect timeout settings in freetds.conf. For more details, see: http://freetds.schemamania.org/userguide/freetdsconf.htm
But if you are using MS ODBC drivers, probably there's no way to specify timeout values at this time because they don't support Connect Timeoutkeyword in the connection string.
And now, pyodbc provides the following way to specify timeout values:
timeout kwarg in podbc.connect() this represents SQL_ATTR_LOGIN_TIMEOUT in the ODBC spec.
timeout attribute of Connection object this represents SQL_ATTR_CONNECTION_TIMEOUT and SQL_ATTR_QUERY_TIMEOUT in the ODBC spec.
and you can specify timeout values with pyodbc like this:
connect to the database in 3 secondsconn = pyodbc.connect(connstr, timeout=3)# set connection/query timeout to 5 secondsconn.timeout = 5
So it might be a good idea to slightly modify the backend as above to accept these timeout-related options in the database settings.
— Reply to this email directly or view it on GitHubhttps://github.com/aurorasoftware/django-pyodbc/issues/18#issuecomment-21917075 .
@dlo I will add support for these timeout-related database options to the backend if you agree with that. What do you think of that?