pythonpyodbcazure-sql-databaseazure-machine-learning-servicecortana-intelligence

What is the name of the driver to connect to Azure SQL Database from pyodbc in Azure ML?


I'm trying to create a 'Reader' alternative to read data from Azure SQL Database using the 'Execute python script' module in Azure ML. While doing so, I'm trying to connect to Azure SQL using pyodbc library.

Here's my code:

def azureml_main(dataframe1 = None, dataframe2 = None):
    import pyodbc   
    import pandas as pd

    conn = pyodbc.connect('DRIVER={SQL Server}; SERVER=server.database.windows.net; DATABASE=db_name; UID=user; PWD=Password')
    SQLCommand = ('''select * from table1 ''')
    data_frame = pd.read_sql(SQLCommand, conn)
    return data_frame,

also tried to use a different driver name: {SQL Server Native Client 11.0}

Here is the error I'm getting:

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

Does anybody know which driver should I use?

Just to make sure, I tried {SQL Server}, {SQL Server Native Client 11.0} and {SQL Server Native Client 10.0} and got the same error

I also tried a different format:

conn = pyodbc.connect('DRIVER={SQL Server}; SERVER=server.database.windows.net; DATABASE=db_name; user=user@server; password=Password')

and

conn = pyodbc.connect('DRIVER={SQL Server Native Client 11.0}; SERVER=server.database.windows.net; DATABASE=db_name; user=user@server; password=Password')

Solution

  • I got an answer from Azure support:

    Currently it is not possible to access SQL Azure dbs from within an “execute python script” module. As you suspected this is due to missing odbc drivers in the execution environment. Suggested workarounds are to a) use reader module or b) export to blobs and use the Azure Python SDK for accessing those blobs http://blogs.msdn.com/b/bigdatasupport/archive/2015/10/02/using-azure-sdk-for-python.aspx

    So currently it it impossible to connect to SQL server from “execute python script” module in Azure-ML. If you like to change it, please vote here