Skip to content

Access Token support (SQL_COPT_SS_ACCESS_TOKEN) #106

@mattmelton

Description

@mattmelton

With pyodbc I can use the following to connection Azure SQL Server:

def get_connection(connection_string, access_token):
    exptoken = b""
    for i in access_token:
        exptoken += bytes({i})
        exptoken += bytes(1)
    tokenstruct = struct.pack("=i", len(exptoken)) + exptoken
    SQL_COPT_SS_ACCESS_TOKEN = 1256
    return pyodbc.connect(connection_string, attrs_before={SQL_COPT_SS_ACCESS_TOKEN: tokenstruct})

SQL_COPT_SS_ACCESS_TOKEN is specific to msodbcsql (documentation here) but unfortunately there's no obvious way for me to set this property with pypyodbc, since the ODBC API is hidden and attrs_before fails with:

  File "...\pypyodbc.py", line 2427, in __init__
    connectString = connectString + key + '=' + value + ';'
TypeError: can only concatenate str (not "dict") to str

Please can you expose the ODBC API?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions