0

I have installed django-pyodbc and configured my database settings as:

  1. DEV: Windows XP (64bit), Python 3.3, MDAC 2.7
  2. DB: Remote MSSQL 2008

    DATABASES = {
        'default': {
            'ENGINE': 'django_pyodbc',
            'HOST': 'my.server.com',
            'PORT': '14330',
            'USER': 'xxx500',
            'PASSWORD': 'passw',
            'NAME': 'xxx500',
            'OPTIONS': {
                'host_is_server': True
            },
        }
    }
    

I can telnet to the server and I can access the database via 3rd party GUI Aqua Data Studio - so I know there is no firewall issue of login issue

When I try to run this command to introspect the legacy database I get this error...

(myProject) :\Users\...>python manage.py inspectdb
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python33\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "C:\Python33\lib\site-packages\django\core\management\__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python33\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python33\lib\site-packages\django\core\management\base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "C:\Python33\lib\site-packages\django\core\management\base.py", line 415, in handle
    return self.handle_noargs(**options)
  File "C:\Python33\lib\site-packages\django\core\management\commands\inspectdb.py", line 27, in handle_noargs
    for line in self.handle_inspection(options):
  File "C:\Python33\lib\site-packages\django\core\management\commands\inspectdb.py", line 40, in handle_inspection
    cursor = connection.cursor()
  File "C:\Python33\lib\site-packages\django\db\backends\__init__.py", line 157, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "C:\Python33\lib\site-packages\django_pyodbc\base.py", line 280, in _cursor
    autocommit=autocommit)
pyodbc.Error: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. (17) (SQLDriverConnect)')

What am I missing? Would appreciate some feedback. Thanks

user2225394
  • 25
  • 1
  • 1
  • 3

3 Answers3

0

I made the following changes:

From

DATABASES = {
'default': {
    'ENGINE': 'django_pyodbc',
    'HOST': 'my.server.com',
    'PORT': '14330',
    'USER': 'xxx500',
    'PASSWORD': 'passw',
    'NAME': 'xxx500',
    'OPTIONS': {
        'host_is_server': True
    },
}
}

To

DATABASES = {
'default': {
    ...
    'HOST': 'my.server.com,14330',
    ...
}
}

and got the utf-8 error that requires commenting out lines 364-367 in the django_pyodbc/base.py file.

user2225394
  • 25
  • 1
  • 1
  • 3
0

I believe that isn't really the solution you'd like to use; modifying the code of django-pyodbc isn't a good idea. That said, be sure you're using the most current fork of django-pyodbc, which can currently be found here:

https://github.com/lionheart/django-pyodbc/

Here's an example DB configuration for settings.py which I've gotten to work on the following platforms (w/FreeTDS / UnixODBC for Linux):

  • Windows 7
  • Ubuntu as a VM under Vagrant
  • Mac OS/X for local development
  • RHEL 5 + 6

Here's the configuration:

DATABASES = {
    'default': {
        'ENGINE': 'django_pyodbc',
        'NAME': 'db_name',
        'USER': 'db_user',
        'PASSWORD': 'your_password',            
        'HOST': 'database.domain.com,1433',
        'PORT': '1433',
        'OPTIONS': {
            'host_is_server': True,
            'autocommit': True,
            'unicode_results': True,
            'extra_params': 'tds_version=8.0'
        },
    }
}
FlipperPA
  • 13,607
  • 4
  • 39
  • 71
0

You need to add the driver to your database back end.

DATABASES = {
    'default': {
      .......
      'OPTIONS': {
       .......
       'driver' : 'SQL Server',
       .......
       },
    }
  }

String. ODBC Driver to use. Default is "SQL Server" on Windows and "FreeTDS" on other platforms.

xalien
  • 123
  • 1
  • 8