1

I'm trying to connect to an external SQL Server Express database using the django-pyodbc version at: this github link but I keep getting this error when I run manage.py shell to check if I can execute come ORM commands

Traceback (most recent call last):
File "manage.py", line 10, in <module>
  execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line   443, in execute_from_command_line
  utility.execute()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
  self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
  self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py",line 232, in execute
  output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py",line 371, in handle
  return self.handle_noargs(**options)
File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/shell.py", line 45, in handle_noargs
  from django.db.models.loading import get_models
File "/usr/local/lib/python2.7/site-packages/django/db/__init__.py", line 40, in <module>
  backend = load_backend(connection.settings_dict['ENGINE'])
File "/usr/local/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
  return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/usr/local/lib/python2.7/site-packages/django/db/utils.py", line 93, in __getitem__
  conn = backend.DatabaseWrapper(db, alias)
File "/usr/local/lib/python2.7/site-packages/sql_server/pyodbc/base.py", line 133, in __init__
  self.ops = DatabaseOperations(self)
File "/usr/local/lib/python2.7/site-packages/sql_server/pyodbc/operations.py", line 10, in __init__
  super(DatabaseOperations, self).__init__()
  TypeError: __init__() takes exactly 2 arguments (1 given)

My settings.py has this:

DATABASES = {
    'default': {
       'ENGINE': 'sql_server.pyodbc',
       'NAME': 'DBName',
       'HOST': '192.168.29.1',
       'USER': 'user',
       'PASSWORD': 'pswd',
       'PORT': 1433,
    }
}

DATABASE_OPTIONS = {
    'driver': '/usr/local/lib/libtdsodbc.so',
    'dsn': 'FreeTDS',
    'extra_params': "TDS_VERSION=8.0"
}

I'm completely at a loss as to what I'm supposed to do, so all ideas are welcome. Essentially what I want is to be able to use a small app I've made to interface with the SQL Server database, while being able to use normal DJango ORM commands inplace of pyodbc connection strings (and BTW using pyodbc, I can connect to the SQL Server database without an issue)

2
  • I'm experiencing this exact same issue. Django 1.5 or 1.6, connecting to SQL Server 2008 using avidal's forked django-pyodbc repo. Getting the exact same error you are. Did you solve this? Commented Feb 27, 2014 at 9:54
  • @knite I actually skipped this implementation since the SQL bit wasn't really critical in my project Commented Feb 27, 2014 at 18:14

1 Answer 1

2

it seem to me that you are using the old repo for django-pyodbc at http://code.google.com/p/django-pyodbc/

make sure to cleanly uninstall the old version and then reinstall

pip uninstall sql-server.pyodbc
pip install git+https://github.com/avidal/django-pyodbc.git
Sign up to request clarification or add additional context in comments.

2 Comments

This is very weird. I was pretty sure I'd uninstalled the old copy of django-pyodbc. I'd already moved on from this solution, but thanks for the response.
This caused a new problem for me... django.core.exceptions.ImproperlyConfigured: 'sql_server.pyodbc' isn't an available database backend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.