0
votes

I'm having trouble connecting to a SQL Server database through python manage.py dbshell / loaddata.

I'm set up on Ubuntu with FreeTDS, unixODBC, pyodbc (3.0.7) and django-pyodbc from here: https://github.com/lionheart/django-pyodbc/

I can successfully run syncdb and South migrations. However, when I try to run the dbshell or loaddata, I get this error:

[IM002][unixODBC][Driver Manager]Data source name not found, and no default driver specified
[ISQL]ERROR: Could not SQLConnect

I can connect from the command line using isql and tsql. Any ideas on what I'm missing?

1

1 Answers

0
votes

So, I figured out the problem.

If you want to use dbshell or loaddata, you need to use a named DSN instead of just a host. I had this set up in /etc/freetds.conf, /etc/odbcinst.ini, and /etc/odbc.ini correctly, so tsql and isql were working.

I was using this default DATABASE in settings.py:

    'ENGINE': 'django_pyodbc',
    'NAME': 'db_name',
    'USER': 'user_name',
    'PASSWORD': 'pw',
    'HOST': 'hostname.domain.com,1433',
    'PORT': '1433',
    'OPTIONS': {
        'host_is_server': True,
        'autocommit': True,
        'unicode_results': True,
        'extra_params': 'tds_version=7.2'
    },

I had to change it to:

    'ENGINE': 'django_pyodbc',
    'NAME': 'db_name',
    'USER': 'user_name',
    'PASSWORD': 'pw',
    'PORT': '1433',
    'OPTIONS': {
        'host_is_server': True,
        'dsn': 'dsn_name',
        'autocommit': True,
        'unicode_results': True,
        'extra_params': 'tds_version=7.2'
    },

You will notice the first (broken) example uses a 'HOST', while the second (working) example uses a 'dsn' under 'OPTIONS."