dotnetcore / dotnetcore/EasyCaching

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

Open
#319 2 comments 0 reactions 0 assignees View on GitHub
area-sqlite bug
Dominant language
C#
Stars
2.1k
Forks
336
PR merge metrics
No merged PRs in 30d

Description

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`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.