Closed carlashley closed 9 months ago
Could you try using the official Microsoft ODBC Driver for SQL Server and see if the same crash reproduces there?
Ah, seems like Microsoft ships their ODBC driver via homebrew (I can't use homebrew in my org on Macs for various internal reasons). I'll see if I can install it without homebrew and update the ticket if it works.
You can download driver directly from the links in here: https://github.com/microsoft/homebrew-mssql-release
Sorry I haven't got back, got distracted with other issues.
I've installed the MSSQL driver into /usr/local
matching all the relevant paths per the downloaded arm64
tarball that the MS homebrew recipe downloads, and I've configured odbcinst.ini with the driver details, etc, but I bump into the same problem as #1116 , except of course all the file paths are based in /usr/local/
...
>>> import pyodbc
>>> pyodbc.drivers()
['FreeTDS', 'ODBC Driver 18 for SQL Server']
>>>
[host]:lib # otool -L /usr/local/bin/odbcinst
/usr/local/bin/odbcinst:
/usr/local/lib/libodbcinst.2.dylib (compatibility version 3.0.0, current version 3.0.0)
/usr/local/lib/libltdl.7.dylib (compatibility version 11.0.0, current version 11.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1336.0.0)
[host]:lib # lipo -info /usr/local/lib/libmsodbcsql.18.dylib
Non-fat file: /usr/local/lib/libmsodbcsql.18.dylib is architecture: arm64
[host]:lib # otool -L /usr/local/bin/isql
/usr/local/bin/isql:
/usr/local/lib/libodbc.2.dylib (compatibility version 3.0.0, current version 3.0.0)
/usr/local/lib/libltdl.7.dylib (compatibility version 11.0.0, current version 11.1.0)
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libedit.3.dylib (compatibility version 2.0.0, current version 3.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1336.0.0)
[host]:lib # otool -L /Library/Frameworks/Python.framework/Versions/Current/lib/python3.12/site-packages/pyodbc.cpython-312-darwin.so
/Library/Frameworks/Python.framework/Versions/Current/lib/python3.12/site-packages/pyodbc.cpython-312-darwin.so (architecture x86_64):
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1600.151.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1336.0.0)
/Library/Frameworks/Python.framework/Versions/Current/lib/python3.12/site-packages/pyodbc.cpython-312-darwin.so (architecture arm64):
/usr/local/lib/libodbc.2.dylib (compatibility version 3.0.0, current version 3.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1600.151.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1336.0.0)
[host]:lib # odbcinst -j show
unixODBC 2.3.12
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /Users/[redacted]/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
[host]:lib # cat /usr/local/etc/odbcinst.ini
[FreeTDS]
Description=FreeTDS Driver
Driver=/usr/local/lib/libtdsodbc.so
Setup=/usr/local/lib/libtdsodbc.so
[ODBC Driver 18 for SQL Server]
Description=Microsoft ODBC Driver 18 for SQL Server
Driver=/usr/local/lib/libmsodbcsql.18.dylib
[host]:msodbcsql-18.3.2.1-arm64 # isql -v -k "DRIVER={ODBC Driver 18 for SQL Server};DSN=[redacted];UID=[redacted];PWD=[redacted];SERVER=[redacted]"
[08001][Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: [OpenSSL library could not be loaded, make sure OpenSSL 1.0, 1.1, or 3.0 is installed]
[08001][Microsoft][ODBC Driver 18 for SQL Server]Client unable to establish connection. For solutions related to encryption errors, see https://go.microsoft.com/fwlink/?linkid=2226722
[ISQL]ERROR: Could not SQLDriverConnect
[host]:msodbcsql-18.3.2.1-arm64 # isql -v -k "DRIVER={ODBC Driver 18 for SQL Server};DSN=[redacted];UID=[redacted];PWD=[redacted];Encrypt=YES;TrustServerCertificate=YES;sslca=/usr/local/etc/openssl/certs/[redacted].crt;SERVER=[redacted]"
[08001][Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: [OpenSSL library could not be loaded, make sure OpenSSL 1.0, 1.1, or 3.0 is installed]
[08001][Microsoft][ODBC Driver 18 for SQL Server]Client unable to establish connection
[01S00][Microsoft][ODBC Driver 18 for SQL Server]Invalid connection string attribute
[ISQL]ERROR: Could not SQLDriverConnect
I'm not bothered by the openssl
error thrown by isql
as it suggest to me that isql
is working fine with the MS driver (but fails because it can't find openssl libraries where it's expecting them, this is a "stock" install of macOS with the standard openssl included in the OS).
This Can't open lib '/usr/local/lib/libmsodbcsql.18.dylib' : file not found
error occurs in Python 3.10.10 to 3.12 (the system hardware and OS is the same, M1 Mac, macOS 14.0).
Just noting here, I've installed pymssql
v 2.1.5 (compiled), to test if that would work, and it is working fine.
Some further info:
tsql -S [freetds server] -U [user] -P [password]
with dumplog enabled:
Log:
log.c:187:Starting log file for FreeTDS 1.4.2
on 2023-10-31 13:53:08 with debug flags 0x4fff.
iconv.c:371:tds_iconv_open(0x12b604630, UTF-8, 1)
iconv.c:356:Using trivial iconv
iconv.c:202:local name for ISO-8859-1 is ISO-8859-1
iconv.c:202:local name for UTF-8 is UTF-8
iconv.c:202:local name for UCS-2LE is UCS-2LE
iconv.c:202:local name for UCS-2BE is UCS-2BE
iconv.c:390:setting up conversions for client charset "UTF-8"
iconv.c:392:preparing iconv for "UTF-8" <-> "UCS-2LE" conversion
iconv.c:431:tds_iconv_open: done
net.c:391:Connecting with protocol version 7.4
net.c:318:Connecting to [redacted] port 1433
net.c:340:tds_setup_socket: connect(2) returned "Operation now in progress"
net.c:528:tds_open_socket() succeeded
packet.c:852:Sending packet
0000 12 01 00 3a 00 00 00 00-00 00 1a 00 06 01 00 20 |...:.... ....... |
0010 00 01 02 00 21 00 0c 03-00 2d 00 04 04 00 31 00 |....!... .-....1.|
0020 01 ff 09 00 00 00 00 00-01 4d 53 53 51 4c 53 65 |.<FF>...... .MSSQLSe|
0030 72 76 65 72 00 40 1f 00-00 00 |rver.@.. ..|
packet.c:410:Received packet
0000 04 01 00 2b 00 00 01 00-00 00 1a 00 06 01 00 20 |...+.... ....... |
0010 00 01 02 00 21 00 01 03-00 22 00 00 04 00 22 00 |....!... ."....".|
0020 01 ff 0e 00 07 ff 00 00-01 00 00 |.<FF>...<FF>.. ...|
login.c:1387:detected crypt flag 1
tls.c:1019:setting default openssl cipher to:HIGH:!SSLv2:!aNULL:-DH
tls.c:147:in tds_push_func_login
tls.c:117:in tds_pull_func_login
packet.c:852:Sending packet
<connection established>
However when attempting a connection (now using pyobdc 5.0.1 and Python 3.12):
log.c:187:Starting log file for FreeTDS 1.4.2
on 2023-10-31 13:12:22 with debug flags 0x4fff.
iconv.c:371:tds_iconv_open(0x11d65d550, UTF-8, 1)
iconv.c:356:Using trivial iconv
iconv.c:202:local name for ISO-8859-1 is ISO-8859-1
iconv.c:202:local name for UTF-8 is UTF-8
iconv.c:202:local name for UCS-2LE is UCS-2LE
iconv.c:202:local name for UCS-2BE is UCS-2BE
iconv.c:390:setting up conversions for client charset "UTF-8"
iconv.c:392:preparing iconv for "UTF-8" <-> "UCS-2LE" conversion
iconv.c:431:tds_iconv_open: done
net.c:391:Connecting with protocol version 7.4
net.c:318:Connecting to [redacted] port 1433
net.c:340:tds_setup_socket: connect(2) returned "Operation now in progress"
net.c:528:tds_open_socket() succeeded
packet.c:852:Sending packet
0000 12 01 00 3a 00 00 00 00-00 00 1a 00 06 01 00 20 |...:.... ....... |
0010 00 01 02 00 21 00 0c 03-00 2d 00 04 04 00 31 00 |....!... .-....1.|
0020 01 ff 09 00 00 00 00 00-01 4d 53 53 51 4c 53 65 |.<FF>...... .MSSQLSe|
0030 72 76 65 72 00 c2 1d 00-00 00 |rver.<C2>.. ..|
packet.c:410:Received packet
0000 04 01 00 2b 00 00 01 00-00 00 1a 00 06 01 00 20 |...+.... ....... |
0010 00 01 02 00 21 00 01 03-00 22 00 00 04 00 22 00 |....!... ."....".|
0020 01 ff 0e 00 07 ff 00 00-01 00 00 |.<FF>...<FF>.. ...|
login.c:1387:detected crypt flag 1
tls.c:1019:setting default openssl cipher to:HIGH:!SSLv2:!aNULL:-DH
tls.c:1035:handshake failed with -1 12 1
If I use Python 3.10, as per earlier comments, it works fine.
Compile-time settings (established with the "configure" script)
Version: freetds v1.4.2
freetds.conf directory: /usr/local/etc
MS db-lib source compatibility: no
Sybase binary compatibility: no
Thread safety: yes
iconv library: no
TDS version: auto
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: no
OpenSSL: yes
GnuTLS: no
MARS: yes
I've been able to get approval to use homebrew
on a test machine....
Running macOS 14.1 (23B74) with brew versions of unixodbc
installed and the Microsoft SQL driver installed as per, and installing pyodbc
with pip3 install --no-binary :all: pyodbc
, can confirm that pyodbc
works as expected.
I need to do a test on another machine that is a fresh macOS install to verify if the self compiled unixodbc + freetds is failing and that it's not something related to my OS install.
We've just released 5.1.0 with binaries for both ARM & Intel Macs. Can you try this version?
I'm going to close this for now since it is pretty old and we have other Mac issues and discussions. Feel free to reopen if this is still a problem.
Please first make sure you have looked at:
Environment
To diagnose, we usually need to know the following, including version numbers. On Windows, be sure to specify 32-bit Python or 64-bit:
Issue
When calling
pyodbc.connect(dsn, ansi=True)
, it terminates withzsh: bus error python3
as the error; expected behaviour is the connection is established without crashing.ODBC trace:
I haven't been able to catch a crash log for Python 3.12, but the issue occurs with pyodbc 4.0.39 and Python 3.11.6. Issue is not present when using pyodbc 4.0.34 and Python 3.10.10.