3

I am querying a view which will return huge data and takes more than 1 minute to complete.

I am executing the query with django.db.connection.cursor() since this is not my default db. After 30 seconds I am getting an exception 'Query timeout expired'. I think 30 seconds is the default timeout of django-mssql. Is there a way to increase timeout period or is there any other way.

Can't work on SQL query because it is implemented by another party. Only a view is exposed.

str(Exception) is "(-2147352567, 'Exception occurred.', (0, u'Microsoft OLE DB Provider for SQL Server', u'Query timeout expired', None, 0, -2147217871), None)"

1 Answer 1

6

You can adjust the COMMAND_TIMEOUT in the database config, in your django settings file. Example of using COMMAND_TIMEOUT:

DATABASES = {
'default': {
    'NAME': DATABASE_NAME,
    'ENGINE': 'sqlserver_ado',
    'HOST': DATABASE_HOST,
    'USER': DATABASE_USER,
    'PASSWORD': DATABASE_PASSWORD,
    'COMMAND_TIMEOUT': DATABASE_COMMAND_TIMEOUT,
   }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, It worked. What exactly is DATABASE_COMMAND_TIMEOUT ? Seconds, milliseconds ? Also can we set it as no timeout ? @AdrianGhiuta
DATABASE_COMMAND_TIMEOUT is seconds. Afaik, a value for it is required (it will default to 30s otherwise), it cannot be set to no timeout.
It can be set to Zero, which means no timeout

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.