-
Install and register the FreeTDS driver for unixODBC.
apt-get install tdsodbc odbcinst -i -d -f /usr/share/tdsodbc/odbcinst.ini
-
(Optional) Test the DSN-less connection with pyodbc.
apt-get install python-pyodbc >>> import pyodbc >>> pyodbc.connect("DRIVER=FreeTDS;SERVER=...;PORT=1433;UID=...;PWD=...;DATABASE=...") <pyodbc.Connection object at ...> apt-get remove python-pyodbc
-
In your project's virtualenv, install django-pyodbc.
apt-get install python-dev unixodbc-dev # If you have an old version of pip: pip install django-pyodbc # If you have a recent version of pip: pip install --allow-external pyodbc --all-unverified pyodbc django-pyodbc
-
Edit the DATABASES setting in your Django project.
DATABASES = { '...': { 'ENGINE': 'django_pyodbc', 'NAME': '...', 'HOST': '...', 'PORT': 1433, 'USER': '...', 'PASSWORD': '...', 'OPTIONS': { 'host_is_server': True, } } }
-
Test the connection in
./manage.py shell
.>>> from django.db import connection >>> cursor = connection.cursor() >>> cursor.execute("SELECT 2 + 2") <pyodbc.Cursor object at ...> >>> cursor.fetchall() [(4,)] >>> cursor.close()
-
-
Save raminfp/df720c026bab874fc10f6a9aae36125b to your computer and use it in GitHub Desktop.
Connecting a Django application to a Microsoft SQL Server database from Debian GNU/Linux
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment