David AM
David AM

Reputation: 105

Django Connection not working properly with Azure Active Directory

I'm trying to put my application out in production. It was fully working when I was working locally, and it also worked when I did it in a test database in azure.

The problem is that now, when I want to use the actual production database, it is sending me errors.

I'm pretty sure that I have all the settings correct, but I think this is something I have to change inside my Azure settings, but I can't find out why.

This is my connection:

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'Reconciliation',
        'USER': '[email protected]',
        'PASSWORD': 'pa$$words$$$.',
        'HOST': 'mycompany.database.windows.net',
        'PORT': '',

        'OPTIONS': {
            'driver': 'ODBC Driver 17 for SQL Server',
        },
    },
}

This is the error I'm getting:

[HY000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Cannot open server "myserver" requested by the login.  The login failed. (40532); [HY000] [Microsoft][ODBC Driver 17 for SQL Server]Invalid connection string attribute (0)')

Should I be changing some settings inside Azure for it to work?

Upvotes: 0

Views: 576

Answers (1)

David AM
David AM

Reputation: 105

The default was correct. I had to add this so it worked:

        'OPTIONS': {
            'driver': 'ODBC Driver 17 for SQL Server',
            "extra_params": 'Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;Authentication=ActiveDirectoryPassword',
        },

The options will depend on the service you are using. I went into the azure portal and there they specified which where this extra parameters I needed to add.

Upvotes: 3

Related Questions