EasyCaching icon indicating copy to clipboard operation
EasyCaching copied to clipboard

BeginTransaction can only be called when the connection is open error in SqLite provider

Open springjazzy opened this issue 4 years ago • 2 comments

I keep getting BeginTransaction can only be called when the connection is open error while using SqLite provider,

How does it supposed to work? What am I doing wrong?

https://github.com/dotnetcore/EasyCaching/blob/159a9306538dcef59a714a8d17465197ba5b4417/src/EasyCaching.SQLite/Configurations/SQLiteDatabaseProvider.cs#L55

Here we create "connection pool" per ManagedThreadId. All connection by default are closed.

Here is the only place I found where connection is explicitly opened: https://github.com/dotnetcore/EasyCaching/blob/159a9306538dcef59a714a8d17465197ba5b4417/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs#L93

In, asp.net core environment I frequently encounter thread switching which cause SQLiteDatabaseProvider not to use opened connection but to create new connection (closed). Later when BeginTransaction is called https://github.com/dotnetcore/EasyCaching/blob/159a9306538dcef59a714a8d17465197ba5b4417/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs#L251 I get BeginTransaction can only be called when the connection is open exception.

springjazzy avatar Jul 29 '21 18:07 springjazzy

@springjazzy Thanks for your interest in this project.

We will take a look ASAP.

This SQLite issue is related with #260 .

BTW, which version are you using?

catcherwong avatar Jul 30 '21 00:07 catcherwong

Thanks for reply. I'm using 1.3.0 version.

springjazzy avatar Jul 30 '21 06:07 springjazzy