直接执行自定义SQL时,django-mssql中的查询超时已过期 [英] Query timeout expired in django-mssql when executing custom SQL directly
问题描述
我正在查询一个视图,该视图将返回大量数据,并且需要1分钟以上的时间才能完成.
I am querying a view which will return huge data and takes more than 1 minute to complete.
我正在使用django.db.connection.cursor()执行查询,因为这不是我的默认数据库.30秒后,我收到一个异常查询超时已过期".我认为30秒是django-mssql的默认超时时间.有没有办法增加超时时间,还是有其他办法.
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.
因为它是由另一方实现的,所以不能用于SQL查询.仅显示一个视图.
Can't work on SQL query because it is implemented by another party. Only a view is exposed.
str(Exception)
是(-2147352567,'发生了异常.',(0,'SQL Server的Microsoft OLE DB提供程序',u'查询超时已过期',无,0,-2147217871),无)"
str(Exception)
is "(-2147352567, 'Exception occurred.', (0, u'Microsoft OLE DB Provider for SQL Server', u'Query timeout expired', None, 0, -2147217871), None)"
推荐答案
您可以在django设置文件中的数据库配置中调整COMMAND_TIMEOUT.使用COMMAND_TIMEOUT的示例:
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,
}
}
这篇关于直接执行自定义SQL时,django-mssql中的查询超时已过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!