I have been given an ODBC connection string to connect to a database. However, I am having difficulty in having my Django app to connect to it. What are the proper steps to have my app to connect to it? Am I missing anything in my code?
This is my connection string:
Driver={SQL Anywhere 17};uid=user;pwd=secret;server=databasename;astart=No;host=127.0.0.1;port=1234
Using a test script that uses pyodbc I am able to connect to the database. However, when I attempt to modify the settings.py file for my app, it fails to connect to the database.
Requirements.py
django~=2.1.4
pyodbc~=4.0.25
django-pyodbc-azure~=2.1.0.0
Settings.py
#First Attempt
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'HOST': '127.0.0.1,1234',
'USER': 'user',
'PASSWORD': 'secret',
'NAME': 'databasename',
'PORT': '1234',
'OPTIONS': {
'driver' : 'SQL Anywhere 17',
'host_is_server': 'True',
},
}
}
#Second Attempt
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'HOST': '',
'NAME': 'databasename;',
'PORT': '',
'OPTIONS': {
'host_is_server': 'True',
'dsn': 'Driver={SQL Anywhere 17};uid=user;pwd=secret;server=databasename;astart=No;host=127.0.0.1;port=1234'
},
}
}
For my first attempt, I get the following error:
django.db.utils.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
For my second attempt, I am getting the following error:
django.db.utils.Error: ('IM010', '[IM010] [Microsoft][ODBC Driver Manager] Data source name too long (0) (SQLDriverConnect)')
I am unsure what I am doing wrong. Any help would be greatly appreciated.