I'm having problems connecting my Django project to SQL Server 2008 when using IIS to serve Django and django-mssql to handle transactions. I am using IIS 7 and 64 bit ActivePython 2.7.
Here is my list of installed packages:
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
And here is the last bit of the stack trace:
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.
If I add the sqlserver_ado
folder to C:\Python27\Lib\site-packages\django\db\backends
and change my database settings in settings.py
from 'ENGINE': 'sqlserver_ado',
to 'ENGINE': 'django.db.backends.sqlserver_ado',
, then I get a slightly different stack trace.
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.
If I connect to a sqlite database instead of SQL Server, the application works fine.
If I run the project using the development server, connecting to SQL Server works fine.
So it seems the problem is the combination of IIS / PyISAPIe and django_mssql.
Several other questions have mentioned similar issues. Each of these were solved by somehow getting python dlls on the system path. I tried (both by checking the path and copying the files into c:\python2.7
, but I get the same error.
For a last bit of info, here is sys.path
for the development server version and the IIS / PyISAPIe version.
Development (works):
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 (fails):
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
Any tips or suggestions of where to go from here would be appreciated. I'm going to try out normal (i.e. non-Active) Python next to see if that makes a difference.
Installing 64 bit python from scratch and following the advice here worked. The problem must have been some goofiness with Active Python.
There was one thing I did notice that may be helpful.
C:\Python27\Lib\site-packages
contained a folder named pywin32_system32
which contained the executables that needed to be copied to C:\Python27
to solve the problem.I also noticed that the directories that are there for both installation methods (win32
, win32com
, and win32comext
) contain slightly different files.
I hope this saves someone else some pain in the future.