0

I can't use built-in connection pooling of SQLite. It doesn't work with WPF apps. It is stated in the source code of SQLiteConnectionPool class.

I would like to implement my own connection pool for SQLite connections using Linq2DB DataConnection class. What is the best way to implement this?

I can see DataContext doesn't have constructor which accept DataConnection. Should roll my own implementation of IDataContext which uses ConnectionPool internally to get the connection?

ekalchev
  • 762
  • 7
  • 24

1 Answers1

1

If you want to control connection creation, I would recommend to subclass SQLiteDataProvider and override CreateConnectionInternal method to provide your own logic for new connection creation. This will cover all cases when linq2db needs to create connection, not just DataConnection or DataContext calls.

PS: not sure which statement you mean, as I don't see any WPF or cannot notes in SQLiteConnectionPool's code.

  • 1
    It says: /// /// This default method implementations in this class (i.e. SQLiteConnectionPool) should not be used by /// applications that make use of COM (either directly or indirectly) due /// to possible deadlocks that can occur during finalization of some COM /// objects. /// And WPF is COM based – ekalchev Aug 05 '19 at 08:53
  • Where do you get that WPF is COM based? Do you have a reference? – C Perkins Aug 06 '19 at 03:18
  • Okay, I see that WPF relies upon optimized, unmanaged interface to DirectX, a COM-based API. But those interfaces are used by the WPF rendering system and should be completely separate from managed threads were you would be using the connection pool to do DB work. Unless you're doing something really strange or incorrect calls to the UI, no COM object's finalization should be entangled with the sqlite connections. Are you establishing explicit async callbacks on COM objects or dependents on the same threads as the db connections? – C Perkins Aug 06 '19 at 03:44