0

For the past few weeks I have been developing a Django web app on Windows environment and now I am trying to deploy it to AWS.

The app's data base is a Azure SQL database and the configuration in the setting.py file is like this:

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'nameofdatabase',
        'HOST': 'nameofdatabase.database.windows.net',
        'PORT': '1433',
        'USER': 'user',
        'PASSWORD': 'password',
        'OPTIONS': {
            'driver': 'ODBC Driver 13 for SQL Server',
        }
    }
}

And this is the error I got when trying to access the app. I set DEBUG=TRUE so I can see the exception here.

Django Version: 2.1.3
Exception Type: InterfaceError
Exception Value: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')
Exception Location: /opt/python/run/venv/local/lib/python3.6/site-packages/sql_server/pyodbc/base.py in get_new_connection, line 307
Python Executable:  /opt/python/run/venv/bin/python3
Python Version: 3.6.7

I know this is something to do with the pyodbc package or SQL driver as well as unixodbc on Amazon Linux.

I'm quite new to programming so hope you guys can shed some light. Thank you!

knl
  • 969
  • 11
  • 35

1 Answers1

0

I have two suggestions:

To ensure you have a driver installed, you should be able to type a command: sudo apt list <pkg_name> to identify if an ODBC driver is installed. If you need to install the Microsoft ODBC Driver on Linux, please see this documentation.

If this is a Python-specific issue, I suggest the following Stack Overflow post: Connecting to Microsoft SQL server using Python

Secondly, you will need to create a firewall rule (if you haven't already) to allow traffic from the AWS public IP address to your Azure SQL Database deployment (Azure SQL Database and SQL Data Warehouse IP firewall rules).

Mike Ubezzi
  • 1,007
  • 6
  • 8
  • Thanks Mike for your suggestion. I have allowed the IP address of AWS to access Azure SQL database. And also, when I try to run the app on my local computer, everything works fine. Does it mean that it shouldn’t be a Python issue? And for the step of installing SQL driver on AWS, may I know which OS should I choose from the list? I know mine is “Amazon Linux AMI”, but I’m not sure which one to choose from the Microsoft guidline page. – knl Mar 22 '19 at 01:13
  • The SQL Driver option is a potential fix here. What ODBC driver is the application using when you run this from your local computer? In looking into Amazon Linux AMI, you have no ability to run pkg utilities from a command line as it is an elastic service, and comes preconfigured. So, either Amazon has a preconfigured ODBC driver that Linux AMI can use to connect to your Azure SQL Database. If you do happen to have command line access to your Amazon Linux AMI instance, look to install the same driver your solution is using locally. This could be solved by running: pip install pyodbc – Mike Ubezzi Mar 22 '19 at 16:57