LiteDB 5 System.IO.IOException:进程无法访问文件

问题描述 投票:1回答:1

[我们目前有一个客户端应用程序,该应用程序由Windows Service和WPF应用程序组成,均使用LiteDB并以.Net Framework 4.8为目标。

Windows服务在本地系统帐户下运行,而WPF应用在用户帐户下运行。

我们选择从4.1.4升级到5.0.7,希望可以更好地支持并发性。

WPF应用程序和Win服务都使用下面的连接字符串通过connection = shared访问相同的LiteDB(读和写):

"Filename=C:\temp\Test-v5.db;password=pass1234;connection=shared"

using (var db = new LiteDatabase(@"Filename=C:\temp\Test-v5.db;password=pass1234;connection=shared"))
{
    ...
}

然而,我们似乎遇到了一个重大问题,似乎找不到其他人遇到相同/相似的问题或其他任何可以解决的问题。

该服务经常轮询数据库以处理和处理WPF应用程序通过读写操作插入的数据。WPF应用程序还读取和写入数据库,但基于用户交互的时间更为分散。

尽管两个应用程序都以相同的方式访问数据库,并且都指定了connection = shared,但由于它们似乎发生冲突,因此我们从这两个应用程序中都获得了异常。

"System.IO.IOException: The process cannot access the file 'C:\temp\Test-v5.db' because it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   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 LiteDB.Engine.StreamPool.<>c__DisplayClass3_0.<.ctor>b__0()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Lazy`1.get_Value()
   at LiteDB.Engine.DiskService..ctor(EngineSettings settings, Int32[] memorySegmentSizes)
   at LiteDB.Engine.LiteEngine..ctor(EngineSettings settings)
   at LiteDB.SharedEngine.OpenDatabase()
   at LiteDB.SharedEngine.Query(String collection, Query query)
   at LiteDB.LiteQueryable`1.<ToDocuments>d__26.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Pixel_Upload_Service.UploadService.GetPendingJobsFromLiteDB(Boolean _allJobs) in D:\Users\Daniel\Desktop\LiteDB v5 Test\Upload Service\UploadService.cs:line 2654"

作为测试此问题并试图弄清楚发生了什么的一个旁注,我们发现两个WPF应用程序从同一个数据库进行读写操作时,我们没有遇到任何异常,但是只要交换一个WPF应用程序, Windows服务,我们开始得到例外。

有人知道我们如何阻止这种情况发生?

c# wpf windows-services litedb
1个回答
0
投票

这是LiteDB本身的错误,此后已进行了修补。

github上的问题可以在这里找到:https://github.com/mbdavid/LiteDB/issues/1656

© www.soinside.com 2019 - 2024. All rights reserved.