Linux (debian) system django with remote connection to the sqlserver database, djangosqlserver

Source: Internet
Author: User

Linux (debian) system django with remote connection to the sqlserver database, djangosqlserver

After nearly one day, I finally solved the problem and wrote it down to the people who needed it.

To install:

Python-odbc: https://github.com/mkleehammer/pyodbcdownload and install

If the SQL. h file cannot be found when installing python-odbc, apt-get install g ++ is required,

This code is written in C ++ and requires a compiler.

Django-pyodbc: install the https://pypi.python.org/pypi/django-pyodbc after download


UnixODBC: odbc database source in http://www.unixodbc.org/. linux

Install:./configure & make install

Or apt-get install unixODBC-dev


FreeTDS: SQL Server Driver in http://www.freetds.org/linux

Install:./configure -- prefix =/usr/local/freetds -- with-tdsver = 8.0 -- enable-msdblib -- with-gnu-ld -- enable-shared -- enable-static

Make & make install

Apt-get install freetds-dev tdsodbc


Configuration:

1. Configure FreeTDS

Find freetds. conf and add it below:

[MYSQLSERVER]
Host = sqlserver Server IP Address
Port = 1433
Tds version = 8.0
Client charset = UTF-8

Add the directory where tsql is located to the environment variable. For example, add a PATH = $ PATH:/usr/local/freetds/bin to the vim/etc/profile directory.

Source/etc/profile to make it take effect immediately

Test whether FreeTDS is successfully installed:

Tsql-C check the installation environment

Tsql-s mysqlserver-H sqlserver database IP-p 1433-U account-P Password

The following information is displayed successfully:

Locale is "en_US.UTF-8"
Locale charset is "UTF-8"
Using default charset "UTF-8"
1>


Enter the SQL command to test it:

Use test_db

Go

Select * from test;

Go

After the installation is successful, continue to the next step.


2. Configure unixODBC

Find odbc. ini odbcinst. ini

In/etc/odbc. ini/etc/odbcinst. ini

Vim/etc/odbcinst. ini

[FreeTDS]
Description = ODBC of FreeTDS for MS-SQLServer
Driver =/usr/local/freetds/lib/libtdsodbc. so

FileUsage = 1


Vim/etc/odbc. ini

[Odbc connection name]
Driver = FreeTDS
ServerName = MYSQLSERVER (connection name configured in FreeTDS)
Database = test_db (Database name)

Test whether the security configuration of unixODBC is successful:

Isql-v odbc connection name account password

The following message is displayed:

+ --------------------------------------- +
| Connected! |
|
| SQL-statement |
| Help [tablename] |
| Quit |
|
+ --------------------------------------- +
SQL>

Write a few SQL statements to test it, but this time you don't need to use test_db, because the database name has already been configured.

Select * from test

You don't need go anymore.


3. After installing python-odbc and django-pyodbc, configure the setting of django (the installation is relatively simple)

'Kids ':{
'Engine': 'django _ pyoddb ',
'Name': 'database name', # This is not required. However, there are restrictions in django that the NAME entry must exist. It does not take effect here. It is actually written in odbc. ini.
'User': 'account ',
'Password': 'Password ',
'Host': '', # This will not take effect, but it is configured in freetds. conf.
'Options ':{
'Driver ': 'freetds ',
'Dsn ': 'odbc connection name', # odbc dsn name defined in your ODBC. ini,
}

Over!




Why are no new tables in the database created when django connects to the sqlserver database?

Setting. py: INSTALLED_APPS = (..., 'app _ name ',)
 
Django always fails to connect to sqlserver. How can this problem be solved?

The engine name is incorrect. ENGINE is a database type. Change to djang. db. backends. sqlserver_ado.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.