1

I am relatively new to python and very new to django.

I am attempting to connect to a MSSQL server with django. I installed django-mssql (maybe it needs to be put somewhere in the directory of the project?).

However, when using the following in my settings.py, I get the error: 'sqlserver_ado' isn't an available database backend.

'default':{
        'ENGINE': 'sqlserver_ado',
        'NAME': 'db_name',
        'USER': 'usr',
        'PASSWORD': 'pwd',
        'HOST': 'host.cloudapp.azure.com',
    }

I have searched extensively to attempt to solve this problem, but other solutions seem to be hidden or possibly out of date (here). I am using a Mac. Any help & or direction would be much appreciated!

a.powell
  • 1,572
  • 4
  • 28
  • 39

2 Answers2

2

That package is not being maintained and this is the newer version to use:

https://pypi.org/project/django-pyodbc-azure/

pip install django-pyodbc-azure

And then use this for your engine:

'ENGINE': 'sql_server.pyodbc'

It also mentions that the Azure hosts are formatted like this:

String. SQL Server instance in "server\instance" (on-premise) or "server.database.windows.net" (Azure SQL Database) format.

dfundako
  • 8,022
  • 3
  • 18
  • 34
  • Sorry that change was simply a typo in the question, not in the actual problem. I changed the question to reflect that. Still not able to find the db – a.powell Oct 09 '18 at 21:32
  • I highly doubt your host name is that generic. For SQL Server, it is the name of your instance, for AWS, it is the name of your specific RDS host. It is not a generic Azure domain like that. – dfundako Oct 09 '18 at 21:34
  • Also, the docs say that it supports MSSQL 2012, but it doesnt mention Azure: https://bitbucket.org/Manfre/django-mssql/ – dfundako Oct 09 '18 at 21:37
  • My host name is not that generic I just masked it. I have successfully connected to the db via python and pymssql many times but not via django. Maybe it just doesn't support azure! Any other solutions to connecting? I have seen connections using `sql_server.pyodbc` but have not been able to get that to work either. – a.powell Oct 09 '18 at 21:40
  • Read the link I put in my answer and read all the dependencies on Django/Python versions. – dfundako Oct 09 '18 at 21:41
  • Thank you. I am able to now run the server. However, this may be an entirely new question, but I get the error when I go to the page: `Can't open lib 'ODBC Driver 13 for SQL Server' : file not found`. Any help?? – a.powell Oct 09 '18 at 21:51
-2

You have to modify your DATABASES dict in project settings

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql', 
    'NAME': 'db_name',
    'USER': 'usr',
    'PASSWORD': 'pwd',
    'HOST': 'host.cloudapp.azure.com',
    'PORT': 'your_port',
}
some_code
  • 124
  • 4
  • If I used `django.db.backends` isn't that just reaching to django's backend framework and not the third-party azure server I am trying to reach?? – a.powell Oct 09 '18 at 21:30