Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble connecting to MS SQL Server with django-mssql

I'm trying to use django-mssql to connect to MS SQL Server 2008 R2 with Django 1.4.2 These are my Database settings:

DATABASE_ENGINE   = 'sqlserver_ado'
DATABASE_NAME     = 'dbtest'
DATABASE_USER     = 'App'
DATABASE_PASSWORD = '*********'
DATABASE_HOST     = 'localhost'
DATABASE_OPTIONS  =  {
            'provider': 'SQLNCLI10',
            'extra_params': 'DataTypeCompatibility=80;MARS Connection=True;',
        } 

DATABASES = {
  'default': {
    'ENGINE':   DATABASE_ENGINE,
    'NAME':     DATABASE_NAME,
    'USER':     DATABASE_USER,
    'PASSWORD': DATABASE_PASSWORD,
    'HOST':     DATABASE_HOST,
    'OPTIONS' : DATABASE_OPTIONS,
  },
}

This is the error I get when I try to syncdb

    Traceback (most recent call last):
  File "C:\Python27\DataSatellite\manage.py", line 11, in <module>
    execute_manager(settings)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 459, in execute_manager
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "C:\Python27\lib\site-packages\django\core\management\commands\syncdb.py", line 57, in handle_noargs
    cursor = connection.cursor()
  File "C:\Python27\lib\site-packages\django\db\backends\__init__.py", line 306, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "C:\Python27\lib\site-packages\sqlserver_ado\base.py", line 193, in _cursor
    self.__connect()
  File "C:\Python27\lib\site-packages\sqlserver_ado\base.py", line 168, in __connect
    use_transactions=self.use_transactions,
  File "C:\Python27\lib\site-packages\sqlserver_ado\dbapi.py", line 151, in connect
    raise OperationalError(e, "Error opening connection: " + connection_string)
sqlserver_ado.dbapi.OperationalError: (AttributeError("'module' object has no attribute 'VARIANT'",), 'Error opening connection: DATA SOURCE=localhost;Initial Catalog=dbtest;UID=App;PWD=*********;PROVIDER=SQLNCLI10;MARS Connection=True;DataTypeCompatibility=80;MARS Connection=True;')
Finished "C:\Python27\DataSatellite\manage.py syncdb" execution.

I've looked everywhere and I cannot seem to understand and fix the problem. I hope someone can help! Thanks!

Edit:

I've already created the database. I've also connected to the database using django-pyodbc, and I've successfully read and written from the database. But django-pyodbc causes problems when I use Apache, which was why I decided to try django-mssql. However, I do not understand the error it comes up with.

My Django (1.4.2) and Python (2.7) installs run on Windows, and I'm using an Apache webserver.

like image 411
lurknobserve Avatar asked Nov 04 '22 09:11

lurknobserve


1 Answers

Update pywin32 to build 217 or greater. I found another question on stackoverflow with the same issue (on another topic):

Python COM server throws 'module' object has no attribute 'VARIANT'

like image 83
vad Avatar answered Nov 12 '22 17:11

vad