mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.89k stars 562 forks source link

Python abnormal termination when connecting to AzureSQL and empty drivers list #1055

Closed marcozanella closed 2 years ago

marcozanella commented 2 years ago

Hi,

pyodbc.drivers() returns an empty list; and when trying to connect regardless, python simply terminates with no apparent error.

I can connect to the Azure SQL Database using both tsql and isql - so, it looks like I have correct odbcinst.ini and odic.ini Although, before resetting to factory defaults this Mac, I could succeed to connect using mssql17 driver

Expectation would be to connect using a sample script as follows: import pyodbc pyodbc.connet('DRIVER={SQL18};SERVER= example.com; DATABASE= sample_db; UID=admin; PWD=password; Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;')

v-chojas commented 2 years ago

Run odbcinst -j and check whether odbcinst.ini it refers to is empty?

on M1

Make sure you are running consistently arm64 or x86 throughout, since those machines can run either x86 (with emulation) or arm64 binaries, but they don't mix in one process. If you have arm64 Python you cannot use x86 driver/DM and vice-versa.

marcozanella commented 2 years ago

@v-chojas , thanks for quick reply odbcinst.ini is populated, and contains the correct data - I can use that via tsql

I can connect with tsql; so I think all is good between unixodbc, mssql18 driver, config files (ini) and the database. Any insight how I could check if one component is ran or compiled for x86?

v-chojas commented 2 years ago

python --version

marcozanella commented 2 years ago

python --version

Python 3.10.3

v-chojas commented 2 years ago
from platform import processor
processor()

Run that in the python interactive prompt. What does it say?

marcozanella commented 2 years ago

@v-chojas, I have made one step forward ... without understanding why, though. Trying to follow your suggestion, I have uninstalled almost everything (all python modules, python itself, unixodbc) - I have ran a Rosetta terminal and eventually reinstalled all these components using again arm64 terminal (it was a mistake) - but now I can list ODBC drivers using pyodbc.drivers() I have not removed, nor edited ini files; they were working before using tsql, they are now - I honestly don't know what could be different now from then.

marcozanella commented 2 years ago

from platform import processor processor()

The result is "arm"

v-chojas commented 2 years ago

It is likely you had x86 driver + DM and were attempting to use with arm64 Python.