Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access Token support (SQL_COPT_SS_ACCESS_TOKEN) #106

Open
mattmelton opened this issue May 19, 2020 · 2 comments
Open

Access Token support (SQL_COPT_SS_ACCESS_TOKEN) #106

mattmelton opened this issue May 19, 2020 · 2 comments

Comments

@mattmelton
Copy link

mattmelton commented May 19, 2020

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?

@braian87b
Copy link
Collaborator

Please try editing locally https://github.com/jiangwen365/pypyodbc/blob/master/pypyodbc.py#L2483

too see if that works for you. feel free to post your findings here.

@jasoncwik
Copy link

Note that this works now so this issue can be closed.

https://gist.github.com/jasoncwik/11b1bbca04723b4de03ae37c4792abdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants