Django的。错误:('IM002','[IM002] [unixODBC] [驱动程序管理器]未找到数据源名称,并且未指定默认驱动程序(0)(SQLDriverConnect)')

时间:2015-07-21 10:12:45

标签: python-2.7 sql-server-2012 ubuntu-14.04 pyodbc django-1.8

连接到MSSQL服务器时收到此错误

我的linux机器详细信息: -

Distributor ID: Ubuntu
Description:    Ubuntu 14.04.2 LTS
Release:        14.04

MSSQL Server DB详细信息:

version : 2012

错误:

 django.db.utils.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')

Python2.7

Driver: pyodbc == 3.0.10
django-pyodbc-azure == 1.8.3.0 django-mssql == 1.6.1 django >= 1.8.3

1 个答案:

答案 0 :(得分:2)

首先,确保安装了所需的软件包(看起来可能如此):

# Install pre-requesite packages
sudo apt-get install unixodbc unixodbc-dev freetds-dev freetds-bin tdsodbc

然后,确保正确配置了/etc/freetds/freetds.conf:

[global]
    # TDS protocol version, use:
    # 7.3 for SQL Server 2008 or greater (tested through 2014)
    # 7.2 for SQL Server 2005
    # 7.1 for SQL Server 2000
    # 7.0 for SQL Server 7
    tds version = 7.2
    port = 1433
    text size = 64512

# A typical Microsoft server
[dbserverdsn]
    host = dbserver.domain.com
    port = 1433
    tds version = 7.2

接下来,确保通过/etc/odbcinst.ini中的FreeTDS正确地说unixODBC:

[FreeTDS]
Description = v0.91 with protocol v7.2
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so

最后,确保/etc/odbc.ini看到您创建的FreeTDS数据源:

[dbserverdsn]
Driver = FreeTDS
Server = dbserver.domain.com
Port = 1433
TDS_Version = 7.2

如果您遇到问题,请尝试使用' tsql'和' isql'命令行实用程序并发布您收到的任何错误。希望这有效。

如果问题出在Django的配置上,请发布您的Django DATABASES设置以供审核。