How did I access MSSQL database from django pyodbc on windows 7 64-bit:


This is how I got it to work after hours of googling and trying

prerequisites: 
  1. Python and Django are installed.
  2. An accessible MSSQL database. 
  3. pyodbc-1.4 installed (google it :D ).

in django settings file (settings.py)

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',

        'NAME': 'db_name',                     
        'USER': 'db_usrname',                     
        'PASSWORD': 'db_password',     

        'HOST': '127.0.0.1',  # database server IP address                  
        'PORT': '',                     
        'OPTIONS':{  'host_is_server': True,    }
    }
}


INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'pyodbc',
     'django.contrib.admin',
}


Comments

Popular Posts