Connect to MSSQL from Django on CentOS



Steps:



  1. run the below commands in the terminal (it will install needed packages).
    1. yum install python python-devel libxml2 libxml2-devel python-setuptools zlib-devel wget openssl-devel pcre pcre-devel sudo gcc make autoconf automake 
    2. yum install unixODBC*
    3. yum install freetds*
  2. add the below 3 lines to  /etc/odbcinst.ini (without the numbers and the dot after it)
    1. [FreeTDS]
    2. Description     = FreeTDS
    3. Driver          = /usr/lib64/libtdsodbc.so
  3. add the below to /etc/odbc.ini  (without the numbers and the dot after it)
    1. [TS]
    2. Description = "test"
    3. Driver = FreeTDS
    4. Server = 17.1.10.10
    5. Port = 1433
    6. Database = mydatabase
  4. in the terminal run the below command
    1. isql TS yourusename yourpassword
  5. if you see "SQL>" then out setup is correct
  6. in your Django project in setting.py the database setting in DATABASES section 
DATABASES = {
    'default': {
       'ENGINE': 'sql_server.pyodbc'  
        'NAME': 'mydatabasename',                 
        'USER': 'yourusername',                      # Not used with sqlite3.
        'PASSWORD': 'yourpassword',                  # Not used with sqlite3.
        'HOST': '17.1.10.10',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '1433',  
        'OPTIONS':{  'host_is_server': True,    }                
    },
    }


Have fun :)


Prerequisites:.

  1. Django 1.4 installed
    1. go to django website and download the package
    2. cd to the directory and type python setup.py install
  2. python 2.6 installed
  3. pyodbc installed https://code.google.com/p/pyodbc/downloads/list
    1. download the .zip file and extract it.
    2. cd to the directory and type python setup.py install
  4. django-pyodbc installed https://github.com/avidal/django-pyodbc
    1. download the package and extract it
    2. cd to the directory and type python setup.py install



resources:

http://askubuntu.com/questions/167491/connecting-ms-sql-using-freetds-and-unixodbc-isql-no-default-driver-specified

https://library.linode.com/web-servers/nginx/python-uwsgi/fedora-14?format=print

-sorry if i forgot to mention any :)

Comments

Popular Posts