Some objects are not picklable (see Pickling unpicklable objects). I've had the same issue with Redis connections which seem similar to this, though I'm not sure.

The general advice is to extract the data you need and only pickle that, rather than the connection itself.

Answer from Brian on Stack Overflow
🌐
GitHub
github.com › mkleehammer › pyodbc › issues › 446
TypeError: can't pickle pyodbc.Connection objects · Issue #446 · mkleehammer/pyodbc
August 22, 2018 - Python: 3.6(64 bit) pyodbc: 4.0.23 OS: windows server 2012 R2 DB: SQL server 2012 R2 driver: {SQL Server} I'm Facing issue saying that "TypeError: can't pickle pyodbc.Connection objects" Multithreading using pool=3 Traceback (most recent...
Author: mkleehammer
🌐
GitHub
github.com › mkleehammer › pyodbc › issues › 1398
cannot pickle 'pyodbc.Connection' error when using APScheduler with a database connection · Issue #1398 · mkleehammer/pyodbc
January 8, 2025 - The function fails with the following error: TypeError: cannot pickle 'pyodbc.Connection' object The issue arises because pyodbc.Connection objects cannot be serialized (pickled), and APScheduler with ProcessPoolExecutor tries to pickle arguments passed to the scheduled job function.
Author: mkleehammer
🌐
GitHub
github.com › mkleehammer › pyodbc › wiki › Connection
Connection · mkleehammer/pyodbc Wiki · GitHub
Once a connection to the database ... (specifically a single HDBC). Connections also manage database transactions. Connection objects cannot be pickled....
Author: mkleehammer
🌐
JetBrains
youtrack.jetbrains.com › issue › PY-56522
cannot pickle 'sqlite3.Connection' object in pyCharm
Our website uses some cookies and records your IP address for the purposes of accessibility, security, and managing your access to the telecommunication network. You can disable data collection and cookies by changing your browser settings, but it may affect how this website functions.
Find elsewhere
🌐
GitHub
github.com › mkleehammer › pyodbc › issues › 508
Multiprocessing, cursor.fetcall and 'TypeError(“can't pickle pyodbc.Row objects”,)' · Issue #508 · mkleehammer/pyodbc
January 16, 2019 - Using logger i can see that it returns all the data but it shows: MaybeEncodingError: Error sending result: '[[(Decimal('14674'), u'\u0391', u'\u03a7\u039b', 1, 101, 4256815.0, 464554.0, u'117275892689', Decimal('187143225'), Decimal('1001002488331661'), u'1.31670565', u'\u0395\u039b\u0395\u03a5\u0398. \u0392\u0395\u039d\u0399\u0396\u0395\u039b\u039f\u03a5 46'),......]]'. Reason: 'TypeError("can't pickle pyodbc.Row objects",)'
Author: mkleehammer
🌐
Google Code
code.google.com › archive › p › pyodbc › wikis › Objects.wiki
Google Code Archive - Long-term storage for Google Code Project Hosting.
Archive · Skip to content · The Google Code Archive requires JavaScript to be enabled in your browser · Google · About Google · Privacy · Terms
🌐
Stack Overflow
stackoverflow.com › questions › 71523537 › airflow-typeerror-cannot-pickle-pyodbc-cursor-object
python 3.x - airflow TypeError: cannot pickle 'pyodbc.Cursor' object - Stack Overflow
I am using pyodbc for my database connectivity check ... By chance are you doing something like result = cursor.execute("SELECT …") and then passing result to some method that tries to pickle it? ... I was trying to use the cursor object outside a function call, that was causing the problem, and multiple incorrect calls was also one of the reason
🌐
Jod
jod.al › 2011 › 03 › 06 › pickling-multiprocessing-connection-objects
Pickling multiprocessing Connection objects - jod.al
March 6, 2011 - """ def __init__(self, connection): self._connection = connection def __reduce__(self): (conn_func, conn_args) = multiprocessing.reduction.reduce_connection( self._connection) wrapper_func = _ConnectionWrapperRebuilder(conn_func) return (wrapper_func, conn_args) def __getattr__(self, name): return getattr(self._connection, name) class _ConnectionWrapperRebuilder(object): """ Internal class used by :class:`ConnectionWrapper` to rewrap :class:`multiprocessing.Connection` objects when they are depickled. A function defined inside :meth:`ConnectionWrapper.__reduce__` which takes :attr:`conn_func` from its scope cannot be used, as functions must be defined at the module's top level to be picklable.
🌐
Geek Python
geekpython.in › pickle-module-in-python
Pickle Python Object Using the pickle Module
March 1, 2024 - Now exclude the database connection from the pickling process using the __getstate__ method. The __getstate__ method creates a copy of the object’s dictionary, then removes the connection (state['connection']) and cursor (state['cur']) and returns the dictionary (state).
🌐
Medium
medium.com › devopss-hole › python-multiprocessing-pickle-issue-e2d35ccf96a9
Python “multiprocessing” “Can't pickle…” - TedChen
May 26, 2022 - The ‘pickle’ issue in ‘multiprocessing’ is because of passing objects as arguments between process.
🌐
Brian simulator
brian.discourse.group › support
TypeError: cannot pickle 'sqlite3.Connection' object when running Ray Tune with Jupyter notebook script - Support - Brian simulator
November 18, 2022 - Description of problem I got an “TypeError: cannot pickle ‘sqlite3.Connection’ object” error when running the attached Ray Tune code. The code need to import a notebook script called ttt.ipynb. Such an error won’t show…
🌐
GitHub
github.com › mkleehammer › pyodbc › issues › 649
TypeError when trying to unpickle results with equal column names · Issue #649 · mkleehammer/pyodbc
November 21, 2019 - When trying to unpickle a result ... cannot create 'pyodbc.Row' instances · I noticed that at work where we have a MS SQL Server, but it is possible to reproduce the error with sqlite. import sqlite3 import pickle import pyodbc # create a database conn = sqlite3.connect("db.db") c ...
Author: mkleehammer
🌐
Python
bugs.python.org › issue21975
Issue 21975: Using pickled/unpickled sqlite3.Row results in segfault rather than exception - Python tracker
July 14, 2014 - This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/66174