简体   繁体   中英

Connection busy with results for another command, while MARS Connection is being used

While trying to dumpdata in Django with the following command:

python manage.py dumpdata --all --output /data/django_dump.json --verbosity 3

I get the following error:

CommandError: Unable to serialize database: ('HY000', '[HY000] [Microsoft][ODBC Driver 17 for SQL Server]Connection is busy with results for another command (0) (SQLExecDirectW)')
Exception ignored in: <generator object _cursor_iter at 0x7f1c4112b0c0>
Traceback (most recent call last):
  File "/opt/conda/lib/python3.7/site-packages/sql_server/pyodbc/compiler.py", line 133, in _cursor_iter
    cursor.close()
  File "/opt/conda/lib/python3.7/site-packages/sql_server/pyodbc/base.py", line 500, in close
    self.cursor.close()
pyodbc.ProgrammingError: The cursor's connection has been closed.

Following the advice of this post , here's my database configuration:

DATABASES = {
    'default': {
        'NAME': ...,
        'ENGINE': 'sql_server.pyodbc',
        'HOST': ...,
        'USER': ...,
        'PASSWORD': ...,
        'OPTIONS': {
            'driver': 'ODBC Driver 17 for SQL Server',
            'MARS_Connection': True,
        }
    }
}

Using the MARS connection doesn't seem to help at all. Is my configuration wrong? Is there some other reason this might not work?

Python>=3.6, Django>=2, using MS SQL Server (not sure which version, nothing too old) and django-pyodbc-azure from conda-forge.

I tried around setting the MARS_Connection parameter and this is what finally worked (Django 3.0, django-mssql-backend 2.8.1) ie putting 'extra_params': 'MARS_Connection=Yes' inside of the OPTIONS:

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': os.getenv('DB_NAME'),
        'USER': os.getenv('DB_USER'),
        'PASSWORD': os.getenv('DB_PASSWORD'),
        'HOST': os.getenv('DB_HOST'),
        'PORT': os.getenv('DB_PORT'),
        'TEST': {
            'NAME': os.getenv('DB_NAME'),
        },
        'OPTIONS': {
            'driver': 'ODBC Driver 17 for SQL Server',
            'extra_params': 'MARS_Connection=Yes'
        },
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM