无法使用django-mssql连接到MS SQL Server

时间:2012-12-07 14:19:11

标签: python django sql-server-2008 django-mssql

我尝试使用django-mssql通过Django 1.4.2连接到MS SQL Server 2008 R2这些是我的数据库设置:

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,
  },
}

这是我尝试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.

我到处寻找,我似乎无法理解并解决问题。我希望有人能帮帮忙! 谢谢!

编辑:

我已经创建了数据库。我还使用django-pyodbc连接到数据库,并且我已经成功地从数据库中读取和写入了数据库。但是当我使用Apache时,django-pyodbc会导致问题,这就是我决定尝试使用django-mssql的原因。但是,我不明白它出现的错误。

我的Django(1.4.2)和Python(2.7)安装在Windows上运行,我使用的是Apache网络服务器。

1 个答案:

答案 0 :(得分:2)

更新pywin32以构建217或更高版本。我发现另一个关于stackoverflow的问题有同样的问题(在另一个主题上):

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