sql-serverdjangosql-server-2008django-modelsdjango-mssql

Django SQL Server Error: "Cannot create new connection because in manual or distributed transaction mode."


I have some strange issue with querying SQL Server from django.

When I query db twice in single request, I got errors in some cases. Namely when first db query returns big amount of data, we end up with error while querying db second time.

Details:

We're using Microsoft SQL Server backend for Django (https://bitbucket.org/Manfre/django-mssql/src) running on windows.

We want allow user to filter data from some table ("Activity") via form, display it on the website's table and then show related data from another table ("Frames") on map.

class Frames(models.Model):
...

class Activity(models.Model):
frame_from = models.ForeignKey(Frames, ...)
...

The problem is: when we want to filter larger amount of data from Activity (let's say 200rows x 6 colums), we can not make other queries in the same request on table Frames (MARS is turned on in Django settings.py):

result = Aktywnosci.objects.filter(qset1) 

is always ok, but

path = Frames.objects.filter(qset2) 

when the previous query returned larger amount of data, raises OLE DB Error:

'Microsoft OLE DB Provider for SQL Server' Error: Cannot create new connection because in manual or distributed transaction mode.

PS. Database settings from settings.py:

# Database for this installation. 
DATABASES = {
'default':{
    'ENGINE': 'django.db.backends.sqlserver_ado', 
    'NAME': '***',                      
    'USER': '***',                      
    'PASSWORD': '***',                  
    'HOST': '***',                      
    'PORT': '',                        
    'OPTIONS' : {
        'provider': 'SQLOLEDB',
        'use_mars': True,                    
          }
}
}

PS2. I came across this issue on the google-code page of djang-mssql: http://code.google.com/p/django-mssql/issues/detail?id=79 - but it seems to be solved in new version of package...

What can I do about it?

Thanks in advance


Solution

  • We got the solution at bitbucket: https://bitbucket.org/Manfre/django-mssql/issue/13/ole-db-provider-for-sql-server-error from Michael Manfre - thanks a lot for this.

    The solution is following:

    "SQLOLEDB and MARS doesn't work very well and I intend on changing all of the documentation and defaults to assume a native client driver will be used. Try using the native client; "SQLNCLI10" or "SQLNCLI11".

    DATABASES = {
        'default': {
            'ENGINE': 'sqlserver_ado',
            'NAME': 'mydb',
            'HOST': r'localhost',
            'USER': '',
            'PASSWORD': '',
            'OPTIONS': {
                'provider': 'SQLNCLI10',
                'extra_params': 'DataTypeCompatibility=80;MARS Connection=True;',
            },
        }
    }