Comments (5)
Holy smokes - that's a serious issue. Thanks. I just pushed a fix for this and will make a release tonight.
from pyodbc.
I am unable to reproduce the issue on Ubuntu 20.04 with msodbcsql18 and pyodbc 5.1.0 under Python 3.8 using the official UTF-16LE
alias in the Python docs:
import pyodbc
print(pyodbc.version) # 5.1.0
connection_string = (
"DRIVER=ODBC Driver 18 for SQL Server;"
"SERVER=192.168.0.199;"
"UID=scott;PWD=tiger^5HHH;"
"DATABASE=test;"
"TrustServerCertificate=yes;"
)
enc = "UTF-16LE"
print(sys.getrefcount(enc)) # 4
cnxn = pyodbc.connect(connection_string, encoding=enc)
print(sys.getrefcount(enc)) # 3
However, the docs for encoding say:
The ODBC connection string must be sent to the driver as a byte sequence, hence the Python string must first be encoded using the named encoding.
That is clearly not the case for msodbcsql, so just don't use it.
from pyodbc.
Thank you for your reply.
When looking at your example I see,
print(sys.getrefcount(enc)) # 4
cnxn = pyodbc.connect(connection_string, encoding=enc)
print(sys.getrefcount(enc)) # 3
does this mean the reference count goes down from 4 to 3? This would mean if you close the connection and reconnect 3 times your reference count should be also down to 0.
For Debian 12 I get
import sys
import pyodbc
import sqlite3
con = sqlite3.connect("abc.db")
cur = con.cursor()
cur.execute("CREATE TABLE simple(example TEXT)")
con.close()
print(pyodbc.version)
#py> 5.1.0
connection_string = "Driver=SQLite3;Database=./abc.db"
encoding = "UTF-16LE"
sys.getrefcount(encoding)
#py> 2
cnxn = pyodbc.connect(connection_string, encoding=encoding)
sys.getrefcount(encoding)
#py> Segmentation fault
a similar result.
To the specification of the encoding argument, I used the same as defined in the function header in https://github.com/mkleehammer/pyodbc/blob/master/src/pyodbc.pyi line 982, defined as
def connect(connstring: Optional[str] = None,
/, *, # only positional parameters before, only named parameters after
autocommit: bool = False,
encoding: str = 'utf-16le',
readonly: bool = False,
timeout: int = 0,
attrs_before: Optional[Dict[int, Any]] = None,
**kwargs: Any) -> Connection:
I still believe that the original issue described here #1117 (comment) is related to the reference count of the encoding.
from pyodbc.
As far as I see the following issues are related.
-
#1117
Here the user uses encoding in his connection string, therefore at the second attempt to create a connection fails since encoding seams to be already freed. -
https://stackoverflow.com/questions/70825458/sqlalchemy-pyodbc-connect-fails-without-setting-exception
Seams to be the same issue.
from pyodbc.
This would mean if you close the connection and reconnect 3 times your reference count should be also down to 0.
It doesn't make it to 0; it crashes after 1. When I run my test code in PyCharm I get
enc = "UTF-16LE"
print(sys.getrefcount(enc))
# 4
cnxn = pyodbc.connect(connection_string, encoding=enc)
print(sys.getrefcount(enc))
# 3
cnxn.close()
cnxn = pyodbc.connect(connection_string, encoding=enc)
print(sys.getrefcount(enc))
# 2
cnxn.close()
cnxn = pyodbc.connect(connection_string, encoding=enc)
print(sys.getrefcount(enc))
# 1
#
# Process finished with exit code 139 (interrupted by signal 11:SIGSEGV)
and from a command prompt I get
(venv) gord@gord-dv7:~/PycharmProjects/pyodbc_demo$ python main.py
5.1.0
4
3
2
1
Segmentation fault (core dumped)
from pyodbc.
Related Issues (20)
- im('08001', '[08001] [Microsoft][ODBC Driver 18 for SQL Server]TCP Provider: The wait operation timed out.\r\n (258) (SQLDriverConnect); [08001] [Microsoft][ODBC Driver 18 for SQL Server]Login timeout expired (0); [08001] [Microsoft][ODBC Driver 18 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to 10.0.0.5\\MSSQL16.MSSQLSERVER,1454. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. (258)')
- Raspberry Pi, Ubuntu 22.04 arm64 ODBC18 SSL error HOT 2
- Can't build release artifacts due to cibuildwheel issue HOT 11
- pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/usr/local/lib/libmyodbc8a.so' : file not found (0) (SQLDriverConnect)") HOT 6
- Linux openSUSE Tumbleweed connection to MariaDB stopped working with version 5.x.x HOT 12
- sqlalchemy.exc.OperationalError: (pyodbc.OperationalError) ('08001', '[08001] [Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: [error:0A000102:SSL routines::unsupported protocol] (-1) (SQLDriverConnect)') HOT 1
- Connection is busy with results for another command (0) (SQLExecDirectW) HOT 3
- Transaction is not getting rolled back HOT 7
- MACOS 系统使用 HOT 4
- Memory leak when passing strings within table value parameter to stored proc HOT 9
- Add support for SQLTablePrivileges
- Login Timeout Error when connecting to Synapse database using pyodbc python library in Azure synapse notebook via Managed Identity HOT 1
- PyToCType uses internal function removed from Python 3.13 HOT 3
- I am trying to install pyodbc in MacBook Pro M3 chip - arm64. The drivers are installed succesfully for odbc 13,17 and 18. But pyodbc is not able to detect the drivers.:
- I am trying to install pyodbc in MacBook Pro M3 chip - arm64. The drivers are installed succesfully for odbc 13,17 and 18. But pyodbc is not able to detect the drivers. ERROR: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)") HOT 5
- Executing multiple queries HOT 1
- pyodbc.connect() gives an error when executing it with pytest HOT 1
- InterfaceError: Data source name not found with pyodbc despite working with isql HOT 8
- Multiple threads querying same table takes a long time HOT 19
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyodbc.