【问题标题】:Error "sqlserver_ado isn't an available database backend" (PyISAPIe on IIS)错误“sqlserver_ado 不是可用的数据库后端”(IIS 上的 PyISAPIe)
【发布时间】:2013-02-15 06:25:18
【问题描述】:

在使用 IIS 为 Django 提供服务并使用django-mssql 处理事务时,我在将我的 Django 项目连接到 SQL Server 2008 时遇到问题。我正在使用 IIS 7 和 64 bit ActivePython 2.7

这是我的已安装软件包列表:

Django==1.4.5
distribute==0.6.19
django-mssql==1.2
pypm==1.3.4
pythonselect==1.3
pywin32==214
virtualenv==1.6.1
wsgiref==0.1.2

这是堆栈跟踪的最后一点:

  File "C:\Python27\lib\site-packages\django\db\__init__.py", line 40, in 
    backend = load_backend(connection.settings_dict['ENGINE'])
  File "C:\Python27\lib\site-packages\django\db\__init__.py", line 34, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "C:\Python27\lib\site-packages\django\db\utils.py", line 92, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "C:\Python27\lib\site-packages\django\db\utils.py", line 51, in load_backend
    raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'sqlserver_ado' isn't an available database backend.
Try using django.db.backends.sqlserver_ado instead.
Error was: DLL load failed: The specified module could not be found.

如果我将sqlserver_ado 文件夹添加到C:\Python27\Lib\site-packages\django\db\backends 并将settings.py 中的数据库设置从'ENGINE': 'sqlserver_ado', 更改为'ENGINE': 'django.db.backends.sqlserver_ado',,那么我得到的堆栈跟踪略有不同。

  File "C:\Python27\lib\site-packages\django\db\backends\sqlserver_ado\base.py", line 6, in 
    import dbapi as Database
  File "C:\Python27\lib\site-packages\django\db\backends\sqlserver_ado\dbapi.py", line 49, in 
    import pythoncom
  File "C:\Python27\lib\site-packages\pythoncom.py", line 2, in 
    import pywintypes
  File "C:\Python27\lib\site-packages\win32\lib\pywintypes.py", line 124, in 
    __import_pywin32_system_module__("pywintypes", globals())
  File "C:\Python27\lib\site-packages\win32\lib\pywintypes.py", line 64, in __import_pywin32_system_module__
    import _win32sysloader
ImportError: DLL load failed: The specified module could not be found.

如果我连接到 sqlite 数据库而不是 SQL Server,则应用程序可以正常工作。
如果我使用开发服务器运行项目,则连接到 SQL Server 工作正常。
所以看来问题是 IIS / PyISAPIe 和 django_mssql 的组合。

其他几个问题也提到了类似的问题。通过以某种方式在系统路径上获取 python dll 解决了这些问题。我试过(通过检查路径并将文件复制到c:\python2.7,但我得到了同样的错误。

最后一点信息,这里是 sys.path 用于开发服务器版本和 IIS / PyISAPIe 版本。

开发(作品):

C:\Users\Administrator\Desktop\django test C:\Python27\python27.zip C:\Python27\DLLs C:\Python27\lib C:\Python27\lib\plat-win C:\Python27\lib\lib-tk C:\Python27 C:\Users\Administrator\AppData\Roaming\Python\Python27\site-packages C:\Python27\lib\site-packages C:\Python27\lib\site-packages\win32 C:\Python27\lib\site-packages\win32\lib C:\Python27\lib\site-packages\Pythonwin C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg-info

IIS(失败):

C:\PyISAPIe C:\Windows\system32\python27.zip C:\Python27\Lib C:\Python27\DLLs C:\Python27\Lib\lib-tk c:\windows\system32\inetsrv C:\Python27 C:\Python27\lib\site-packages C:\Python27\lib\site-packages\win32 C:\Python27\lib\site-packages\win32\lib C:\Python27\lib\site-packages\Pythonwin C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg-info c:\inetpub\PyApp

任何关于从这里去哪里的提示或建议将不胜感激。接下来我将尝试使用普通(即非活动)Python,看看是否会有所不同。

【问题讨论】:

    标签: django sql-server-2008 iis-7 django-mssql pyisapie


    【解决方案1】:

    从头开始安装 64 位 python 并按照here 的建议工作。问题一定是 Active Python 出了点问题。

    我确实注意到了一件事可能会有所帮助。

    • 正常安装 python 和 pywin32(使用来自链接站点的可执行文件),C:\Python27\Lib\site-packages 包含一个名为 pywin32_system32 的文件夹,其中包含需要复制到 C:\Python27 以解决问题的可执行文件。
    • 安装 Active Python 时,此目录不存在。

    我还注意到,两种安装方法(win32win32comwin32comext)的目录包含的文件略有不同。

    我希望这可以在将来减轻其他人的痛苦。

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 2016-06-05
      • 1970-01-01
      • 2019-07-16
      • 2019-04-25
      • 1970-01-01
      • 2019-01-30
      • 2011-08-05
      • 1970-01-01
      相关资源
      最近更新 更多