Connect to Dask with user defined DSNs

Viewed 17

I have created local DSNs for connecting to various SQL data sources and cannot determine how to generate a URI for Dask, so I am loading the data into pandas first with the following function.

This connection string works in pyodbc but not Dask: I can pass this pyodbc connection to SQLAlchemy but SQLAlchemy connectables cannot be passed to dask.dataframe.read_sql().

The format of my current connection string is:

DSN=Datasourcename;UID=UserId;PWD=Password

Is there a way to convert this to an sqlachemy connection string I can pass directly to dask?

def Sql_to_dask(constr, query):
    # create the pyodbc connection from a string of format 'DSN=Datasourcename;UID=UserId;PWD=Password'
    con = pyodbc.connect(constr)
    # save the results of the query
    df = pd.read_sql(query, con)
    # convert to dask dataframe
    return dask.dataframe.to_pandas(df, blocksize = 40960)

Is there a way to use dask dataframe read sql with a odbc data source name?

0 Answers
Related