0
votes

I'm new to Django and currently trying to connect my project using python 3.6.4 and Django2.1.2 with SQL server, I tried multiple drivers connectors (libraries installed),

> (irisha) C:\Users\MOHMMED-PC\Desktop\SOUS BUREAU\WEB\irisha\src>pip freeze
adodbapi==2.6.0.7
Django==2.1.2
django-mssql==1.8
django-pyodbc==1.1.3
django-pyodbc-azure==2.1.0.0
django-sqlserver==1.11
pyodbc==4.0.24
pypyodbc==1.3.4
python-tds==1.9.1
pytz==2018.6
six==1.11.0

but without result, the last driver connector I used is pyodbc: Settings,

DATABASES = {
'default': {
    'ENGINE': 'sql_server.pyodbc',
    'NAME': 'iristest',
    'USER': 'sa',
    'PASSWORD': '1234',
    'HOST': '127.0.0.1\test',
    'PORT': '1433',


},}

but some errors appeared:errors

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

thanks for helping me to find a solution.

2
In the previous question you asked, we already commented that you should past the code, not images of code. - Willem Van Onsem
I put the code. - amine
The host contains a non-escaped backslash, what if you write 'HOST': r'127.0.0.1\test',? - Willem Van Onsem
the same error appeared again - amine

2 Answers

0
votes

"If you’re using a database besides SQLite, make sure you’ve created a database by this point. Do that with “CREATE DATABASE database_name;” within your database’s interactive prompt."

More about database setup

0
votes

Finally, I got the solution, the problem is on compatibility between Django and python, when I use pyodbc with Python 3.4.4 and Django==1.8.19 it worked, and this is what I did:

-install Python 3.4.4 - 2015-12-21

in cmd

pip install virtualenv test

virtualenv test

.\Scripts\activate

pip install Django==1.8.19 pip install django-mssql

pip install https://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32

django-admin startproject myproject .

modify setting database

> DATABASES = {    'default': {
>        'ENGINE': 'sqlserver_ado',
>        'HOST': 'MOHAMMED-PC\SQL2014',  # Replace with host name where you have MSSQL server running
>        'NAME': 'test',  # Replace with name of the database on the MSSQL server
>        'USER': 'sa',  # Replace with user name
>        'PASSWORD': '1234',  # Replace with password    }, }