1

I create a new project in django and i was trying to connect to sql server 2019.

So i install sql-server-2019 and after install , i check if ODBC DRIvers was ok, and as you can see , all ok so far.

enter image description here

The next thing i do , was pip install django-pyodbc-azure

enter image description here

I have more packages instaled because i was testing with everyhing i find , and so far i allways have the same error.

enter image description here

it means conn = Database.connect(connstr, django.db.utils.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name was not found and no predefined driver (0) (SQLDriverConnect) was specified)

and here is my settings.py from django:

enter image description here

I'm stuck here, I don't even know what I can to go on

Pedro Mariz
  • 151
  • 2
  • 20
  • 1
    Take a look at this: https://stackoverflow.com/questions/17115632/microsoftodbc-driver-manager-data-source-name-not-found-and-no-default-drive. You can also check out the fork for it: https://github.com/ESSolutions/django-mssql-backend – acw Dec 28 '20 at 16:57
  • 1
    already do it and don't work – Pedro Mariz Dec 28 '20 at 18:28
  • 1
    Please replace the images (other than the first one) with text. Include the full stack trace. – aaron Dec 29 '20 at 01:39
  • 1
    @PedroMariz show DSN de systemas tab and DSN de utilizator tabs as per https://stackoverflow.com/a/41703602/2067976 answer. – Andriy Ivaneyko Jan 04 '21 at 12:23

1 Answers1

6

I would try this:

(1) add 'dsn' entry to DATABASES dictionary as follows:

DATABASES = {
   'default': {
       'ENGINE': 'sql_server.pyodbc',
       ...
       'OPTIONS': {
           'driver': 'ODBC Driver 17 for SQL Server',
           'dsn': 'avariagest',
       },
   }
}

(2) Create a "DSN" named "avariagest":

Go to the "DSN de sistema" tab, in the ODBC administration window, then add and entry called "avariagest" with suitable attributes

Mario Orlandi
  • 5,629
  • 26
  • 29
  • 1
    when I Create a DSN , I choose the option to login with sql user, but I am getting error saying that 'login user failed' and I am pretty sure that login is correct – Pedro Mariz Jan 04 '21 at 10:41
  • 1
    I do believe this has nothing to do with Django, and might be exactly the reason why you're unable to connect from your Django project. I would check the user permissions in the database (and tables). I'm not very familiar with SQL Server configuration, but I think you should check the "roles" properties – Mario Orlandi Jan 04 '21 at 10:47
  • 1
    i was getting a error of ' shared memory' when I was creating the dsn , but already fix it. So right now when I try to make migrations on my Django project , I am getting a error saying "[28000] [Microsoft][ODBC Driver 17 for SQL Server]Invalid connection string attribute (0)')" and "login failed". and just in. case , I already check all the roles to my user. – Pedro Mariz Jan 04 '21 at 11:10
  • Does the DSN configuration dialog supply a "Test connection button" ? In case, did you try it ? Or, you can test the ODBC connection outside the Django context to make sure it's working: "import pyodbc; connstring = 'DSN=mydsn;Uid=my_user_id;Pwd=my_password;'; conn = pyodbc.connect(connstring); print('done')" – Mario Orlandi Jan 04 '21 at 15:37