I am trying to query a table (in an on premise database), which has some encrypted columns, in Python. I don't have any problem querying this data in Microsoft SQL Server Management Studio. Since I have a certificate, I just use Windows authentication to login, and in Additional Connection Parameters, I add "Column Encryption Setting = Enabled". This way I am able to see all the decrypted values.
In Python I am not able to do this. I have tried various parameters in the pyodbc library, but the values always show up encrypted.
What I have tried so far:
conn = pyodbc.connect('Driver={SQL
Server};'
'Server=ServerName;'
'Database=DBName;'
'ColumnEncryption=Enabled;'
'Trusted_Connection=yes;'
'TrustedServerCertificate=yes;')
conn = pyodbc.connect('Driver={SQL
Server};'
'Server=ServerName;'
'Database=DBName;'
'Trusted_Connection=yes;'
'ColumnEncryption=Enabled;')
The values in the Python pandas dataframe still show up encrypted, something like
'\xee\x91\xghk\x00n\xk9.....
ColumnEncryptionbut you don't specify any certificate anywhere. The other settings control the TLS connection and use Windows AuthenticationDriver={ODBC Driver 17 for SQL Server}it should be enough to just useColumnEncryption=Enabled;. The latest driver version is 18