Getting error while connecting to database with freetds and odbc connection

1.8k views Asked by At

Database settings

DATABASES= {
    'default': {
    'ENGINE': 'sql_server.pyodbc',
    #'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    #'ENGINE': 'django.db.backends.sqlite3',
    'NAME': 's',
    'USER': 'test',
    'PASSWORD': 'test',
    'HOST': '*******',
    'OPTIONS':{
        'DRIVER' : 'FreeTDS',
        'DSN' : 'sqlserver',
     },
    },  
}

freetds.conf

[sqlserver] 
host = *******
port = 1433
tds version = 8.0
client charset = UTF-8

etc/odbc.ini

[FreeTDS] 
Description = FreeTDS 
Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/i386-linux-gnu/odbc/libtdsS.so
#Driver = /usr/local/lib/libtdsodbc.so 
#Setup = /usr/local/lib/libtdsS.so 
FileUsage = 1 
CPTimeout = 
CPResuse  = 
client charset = utf-8 

[sqlserver] 
Description = "test" 
Driver = FreeTDS 
#Servername = sqlserver 
Server = *******
Port = 1433 
Database =s 
Trace = No

etc/odbcinst.ini

[FreeTDS]

Description=FreeTDS 
Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
#Driver=/usr/local/lib/libtdsodbc.so 
#Setup=/usr/lib/odbc/libtdsS.so 
DRIVER=FreeTDS 
SERVER=*******
PORT=1433 
DATABASE=s
UID=test 
PWD=test 
tds_version=7.2

[sqlserver]

Description=FreeTDS
Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
#Driver=/usr/local/lib/libtdsodbc.so 
#Setup=/usr/lib/odbc/libtdsS.so 
#DRIVER=sqlserver 
SERVER=*******
PORT=1433 
DATABASE=s
UID=test 
PWD=test 
TDS_Version=8.0

usr/local/etc/odbc.ini

[FreeTDS] 
Driver=/usr/local/lib/libtdsodbc.so 
Servername=sqlserver
Description=FreeTDS SQL Server ODBC driver 
Server=******* 
Port=1433 
Database=s
User=test 
Password=test 
Mars_Connection=No 
Logging=No  
LogFile= 
QuotedId=Yes 
AnsiNPW=Yes 
Language= 
Version7=No 
ClientLB=No 
Encrypt=Yes 
TrustServerCertificate=No 
PrivateKeyFile= 
CertificateFile= 
Entropy= 
Failover_Partner= 
VarMaxAsLong=No 
DisguiseWide=No 
DisguiseLong=No 
DisguiseGuid=No 
Trusted_Connection=No 
Trusted_Domain= 
tds_version = 8.0 

[sqlserver] 
Driver=/usr/local/lib/libtdsodbc.so 
Servername=sqlserver
Description=FreeTDS SQL Server ODBC driver 
Server=******* 
Port=1433 
Database=s
User=test 
Password=test 
Mars_Connection=No 
Logging=No 
LogFile= 
QuotedId=Yes 
AnsiNPW=Yes 
Language= 
Version7=No 
ClientLB=No 
Encrypt=Yes  
TrustServerCertificate=No 
PrivateKeyFile= 
CertificateFile= 
Entropy= 
Failover_Partner= 
VarMaxAsLong=No  
DisguiseWide=No 
DisguiseLong=No 
DisguiseGuid=No 
Trusted_Connection=No 
Trusted_Domain=

usr/local/etc/odbcinst.ini

[FreeTDS] 
Description=FreeTDS Driver 
#Driver=/usr/local/lib/libtdsodbc.so 
#Setup=/usr/lib/odbc/libtdsS.so 
Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/i386-linux-gnu/odbc/libtdsS.so
DRIVER=FreeTDS 
SERVER=*******
PORT=1433 
DATABASE=s
UID=test 
PWD=test 
tds_version=7.2
CPTimeout=
FileUsuage=1

[sqlserver] 
Description=FreeTDS Driver 
Driver=/usr/local/lib/libtdsodbc.so 
#Setup=/usr/lib/odbc/libtdsS.so  
#DRIVER=SQLServer 
SERVER=*******  
PORT=1433 
DATABASE=s
UID=test 
PWD=test 
TDS_Version=8.0

Error(Error page)

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

this is my database connection and i will append the odbc connection. please help me to rectify the error and connection to gets work. Thanks in Advance

1

There are 1 answers

1
sankar On

You need to define your Data Source name under Databases settings which is in settings.py file.

DATABASES={
   'default': {
      'OPTIONS':{
         'DRIVER':'FreeTDS',
         'DSN': 'YOUR DSN NAME'
      },
    },
}