Connection Management - Multiple Databases #317
Unanswered
a-shoemaker
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
It's not clear to me the best practice on connection management, particularly if not dealing with just the one data source provided in the connection string. From the DuckDB documentation, I can see that multiple reader/writer threads from within the same process is supported, but I'm not sure on the handling of the connections with DuckDB.NET.
I have a DuckDBConnection I'm currently opening as in-memory and then attaching to a couple of databases (duckdb file and Ducklake catalog). I want to handle multiple concurrent queries in my service along with updates.
It seems like I would not want/need the overhead of creating a new DuckDbConnection for each request, attaching to the DBs, etc. and also potentially caching that would be advantageous to keep across requests. What I gather is attaching multiple times to the same DuckDB, even within the same process, is a problem. But multiple threads can utilize the same native connection concurrently. I would also like a single in memory DB for the process.
This appears to be what one would want to do:
DataSource=:memory:?cache=sharedDataSource=:memory:?cache=sharedto create a new DuckDbConnectionDuplicate()on the base opened connection?Looking at the underlying connection management code, it seems this would maintain the native DuckDB connection with attached databases and support the concurrent read/writes within the same process. Sharing the cache (i.e., in memory DB) is effectively required as multiple native connections to the same DB, even within the same process, would be a problem.
Am I on the right path here? Comments on what I've got wrong, suggestions, pointing to documentation I missed, etc., would all be appreciated!
Beta Was this translation helpful? Give feedback.
All reactions