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',
},
},
}
[sqlserver]
host = *******
port = 1433
tds version = 8.0
client charset = UTF-8
[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
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
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
[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=
[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
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)')
这是我的数据库连接,我将附加odbc连接。请帮我纠正错误和连接以获得工作。在此先感谢
答案 0 :(得分:1)
您需要在settings.py文件中的数据库设置下定义数据源名称。
DATABASES={
'default': {
'OPTIONS':{
'DRIVER':'FreeTDS',
'DSN': 'YOUR DSN NAME'
},
},
}