You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
along with the text "To pool a individual driver the 'CPTimeout' value is set to a non zero numeric value."
I was messing around with unixODBC 2.3.12 and msodbcsql18 (ODBC Driver 18 for SQL Server) and noticed that CPTimeout = 0 did not disable connection pooling, but CPTimeout = -1 did.
The text was updated successfully, but these errors were encountered:
This appears to be related to the inherent imprecision of timing when a connection is closed and immediately reopened.
fromtimeimportsleepimportpyodbcconnection_string= (
"Driver=ODBC Driver 18 for SQL Server;""Server=192.168.0.199;""Database=test;""UID=scott;""PWD=tiger^5HHH;""TrustServerCertificate=yes;"
)
defget_trans_iso(cnx):
returncnx.execute("""\SELECT CASE transaction_isolation_level WHEN 0 THEN 'Unspecified' WHEN 1 THEN 'ReadUncommitted' WHEN 2 THEN 'ReadCommitted' WHEN 3 THEN 'Repeatable' WHEN 4 THEN 'Serializable' WHEN 5 THEN 'Snapshot' END AS TRANSACTION_ISOLATION_LEVEL FROM sys.dm_exec_sessions where session_id = @@SPID """).fetchval()
pyodbc.pooling=Truepyodbc.odbcversion="3.8"passed=0failed=0foriinrange(20):
cnxn=pyodbc.connect(connection_string)
iso=get_trans_iso(cnxn)
assertiso=="ReadCommitted"cnxn.rollback()
cnxn.set_attr(pyodbc.SQL_ATTR_TXN_ISOLATION, pyodbc.SQL_TXN_SERIALIZABLE)
iso=get_trans_iso(cnxn)
assertiso=="Serializable"cnxn.close()
cnxn=pyodbc.connect(connection_string)
iso=get_trans_iso(cnxn)
ifiso=="ReadCommitted":
passed+=1else:
failed+=1cnxn.close()
sleep(1)
print(f"{passed=}, {failed=}")
With CPTimeout = 0 I see output like
passed=2, failed=18
whereas with CPTimeout = -1 I consistently get
passed=20, failed=0
gordthompson
changed the title
Docs: Using CPTimeout = 0 does not seem to disable connection pooling
Docs: Using CPTimeout = 0 does not consistently disable connection pooling
Aug 16, 2024
How to use connection pooling with unixODBC shows an example of two driver definitions that differ only in that one supports connection pooling and the other one doesn't.
along with the text "To pool a individual driver the 'CPTimeout' value is set to a non zero numeric value."
I was messing around with unixODBC 2.3.12 and msodbcsql18 (ODBC Driver 18 for SQL Server) and noticed that
CPTimeout = 0
did not disable connection pooling, butCPTimeout = -1
did.The text was updated successfully, but these errors were encountered: