question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] The process cannot access the file even on "shared" connection

See original GitHub issue

Version .NET 5, LiteDB 5.0.11

Describe the bug The process cannot access the file 'xxx' because it is being used by another process. during Upserts and Deletes in a very heavily used web app.

Too bad, I though LiteDB is thread safe.

Should I maybe create one static instance of db and keep using it throughout the app? Will it be thread-safe then?

Full exception

System.IO.IOException: The process cannot access the file 'xxxx' because it is being used by another process.
   at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
   at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at LiteDB.Engine.FileStreamFactory.GetStream(Boolean canWrite, Boolean sequencial)
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at LiteDB.Engine.DiskService..ctor(EngineSettings settings, Int32[] memorySegmentSizes)
   at LiteDB.Engine.LiteEngine..ctor(EngineSettings settings)
   at LiteDB.SharedEngine.OpenDatabase()
   at LiteDB.SharedEngine.Delete(String collection, IEnumerable`1 ids)
   at LiteDB.LiteCollection`1.Delete(BsonValue id)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
9600692024commented, Dec 20, 2021

Hi Team,

LiteDb: 5.0.11 .NET Framework 4.8

I am also facing the same issue, and I can able to fix this issue, by applying the code changes given in https://github.com/mbdavid/LiteDB/issues/1893

When we can expect the next release or patch update for this fix.

0reactions
tjmoorecommented, Feb 24, 2023

Still getting this with 5.0.15. Hits certain customers only. Can’t see that they’re on a network share. We store data under %ProgramData% though there’s potential that is on a network share, but our diagnostic logs aren’t showing network drives.

Restarting the services fixes it for a while then happens again and locked out until restarted.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Build error: "The process cannot access the file because it ...
I have found a simple solution which works for me. It goes like this: When the problem occurs, just change the building configuration...
Read more >
FIX The Process Cannot Access the File Because It ... - YouTube
FIX The Process Cannot Access the File Because It Is Being Used by Another Process Commands Shown: net stop http net start http...
Read more >
Process can't access the file because it is being used by ...
To resolve it, first make sure that no users have the file open anywhere, then reboot the machine to make sure it is...
Read more >
The process cannot access the file because it is being ...
The process cannot access the file because it is being used by another process. Microsoft Technologies based on the . NET software framework....
Read more >
[BUG] Cannot access the file... it is being used by another ...
Hello. By default, context is creating with the Direct connection mode which means that the database file cannot be opened by another process....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found