LiteDB 异常问题汇集

c# 利用数据库将程序加密隐藏? - jack_Meng - 博客园 (cnblogs.com)

 

 

1、LiteDB ENSURE: get only index below highest index

===================================================
在 LiteDB.Constants.ENSURE(Boolean conditional, String message) 位置 C:\Users\DELL\Desktop\litedb损坏\LiteDB.Studio-master\LiteDB.Studio\ICSharpCode.TextEditor\Util\TipPainterTools.cs:行号 0
在 LiteDB.Engine.BasePage.Get(Byte index) 位置 C:\Users\DELL\Desktop\litedb损坏\LiteDB.Studio-master\LiteDB.Studio\ICSharpCode.TextEditor\Util\TipPainterTools.cs:行号 0
在 LiteDB.Engine.DataPage.GetBlock(Byte index) 位置 C:\Users\DELL\Desktop\litedb损坏\LiteDB.Studio-master\LiteDB.Studio\ICSharpCode.TextEditor\Util\TipPainterTools.cs:行号 0
在 LiteDB.Engine.DataService.<Read>d__5.MoveNext() 位置 C:\Users\DELL\Desktop\litedb损坏\LiteDB.Studio-master\LiteDB.Studio\ICSharpCode.TextEditor\Util\TipPainterTools.cs:行号 0
在 LiteDB.Engine.BufferReader..ctor(IEnumerable`1 source, Boolean utcDate) 位置 C:\Users\DELL\Desktop\litedb损坏\LiteDB.Studio-master\LiteDB.Studio\ICSharpCode.TextEditor\Util\TipPainterTools.cs:行号 0
在 LiteDB.Engine.DatafileLookup.Load(PageAddress rawId) 位置 C:\Users\DELL\Desktop\litedb损坏\LiteDB.Studio-master\LiteDB.Studio\ICSharpCode.TextEditor\Util\TipPainterTools.cs:行号 0
在 LiteDB.Engine.DatafileLookup.Load(IndexNode node) 位置 C:\Users\DELL\Desktop\litedb损坏\LiteDB.Studio-master\LiteDB.Studio\ICSharpCode.TextEditor\Util\TipPainterTools.cs:行号 0
在 LiteDB.Engine.BasePipe.<LoadDocument>d__6.MoveNext() 位置 C:\Users\DELL\Desktop\litedb损坏\LiteDB.Studio-master\LiteDB.Studio\ICSharpCode.TextEditor\Util\TipPainterTools.cs:行号 0
在 LiteDB.Engine.QueryPipe.<Select>d__2.MoveNext() 位置 C:\Users\DELL\Desktop\litedb损坏\LiteDB.Studio-master\LiteDB.Studio\ICSharpCode.TextEditor\Util\TipPainterTools.cs:行号 0
在 LiteDB.Engine.QueryExecutor.<>c__DisplayClass10_0.<<ExecuteQuery>g__RunQuery|0>d.MoveNext() 位置 C:\Users\DELL\Desktop\litedb损坏\LiteDB.Studio-master\LiteDB.Studio\ICSharpCode.TextEditor\Util\TipPainterTools.cs:行号 0
在 LiteDB.BsonDataReader.Read() 位置 C:\Users\DELL\Desktop\litedb损坏\LiteDB.Studio-master\LiteDB.Studio\ICSharpCode.TextEditor\Util\TipPainterTools.cs:行号 0
在 LiteDB.Studio.TaskData.ReadResult(IBsonDataReader reader) 位置 C:\Users\DELL\Desktop\litedb损坏\LiteDB.Studio-master\LiteDB.Studio\Classes\TaskData.cs:行号 48
在 LiteDB.Studio.MainForm.CreateThread(TaskData task) 位置 C:\Users\DELL\Desktop\litedb损坏\LiteDB.Studio-master\LiteDB.Studio\Forms\MainForm.cs:行号 328

 

 

 

后来发现修复数据库:

注意:

1、修复数据库前,最好备份数据库文件。保留问题原始问题,可以用于做实验。

2、修复时候,语句中的密码一定用原来的密码。语句中密码是重置的密码,修复成功后,update语句时候,报错密码无效。密码无效,一直不能修改

 

 

 

 

 

 

2、LiteDB ENSURE: discarded page must be writable

 引起的issue的原因:修复数据库是用的密码是newpassword,不是数据库原来的密码。

LiteDB ENSURE: discarded page must be writable

===================================================
   在 LiteDB.Constants.ENSURE(Boolean conditional, String message) 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\ConnectionForm.cs:行号 0
   在 LiteDB.Engine.MemoryCache.DiscardPage(PageBuffer page) 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\ConnectionForm.cs:行号 0
   在 LiteDB.Engine.DiskService.DiscardDirtyPages(IEnumerable`1 pages) 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\ConnectionForm.cs:行号 0
   在 LiteDB.Engine.TransactionService.Rollback() 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\ConnectionForm.cs:行号 0
   在 LiteDB.Engine.LiteEngine.AutoTransaction[T](Func`2 fn) 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\ConnectionForm.cs:行号 0
   在 LiteDB.Engine.LiteEngine.Update(String collection, IEnumerable`1 docs) 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\ConnectionForm.cs:行号 0
   在 LiteDB.Engine.LiteEngine.UpdateMany(String collection, BsonExpression transform, BsonExpression predicate) 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\ConnectionForm.cs:行号 0
   在 LiteDB.SqlParser.ParseUpdate() 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\ConnectionForm.cs:行号 0
   在 LiteDB.SqlParser.Execute() 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\ConnectionForm.cs:行号 0
   在 LiteDB.LiteDatabase.Execute(TextReader commandReader, BsonDocument parameters) 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\ConnectionForm.cs:行号 0
   在 LiteDB.Studio.MainForm.CreateThread(TaskData task) 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\MainForm.cs:行号 330

 

 

 

 

3、LiteDB ENSURE: discarded page must be writable

LiteDB ENSURE: discarded page must be writable

===================================================
在 LiteDB.Constants.ENSURE(Boolean conditional, String message) 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\ConnectionForm.cs:行号 0
在 LiteDB.Engine.MemoryCache.DiscardPage(PageBuffer page) 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\ConnectionForm.cs:行号 0
在 LiteDB.Engine.DiskService.DiscardDirtyPages(IEnumerable`1 pages) 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\ConnectionForm.cs:行号 0
在 LiteDB.Engine.TransactionService.Rollback() 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\ConnectionForm.cs:行号 0
在 LiteDB.Engine.LiteEngine.AutoTransaction[T](Func`2 fn) 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\ConnectionForm.cs:行号 0
在 LiteDB.Engine.LiteEngine.Update(String collection, IEnumerable`1 docs) 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\ConnectionForm.cs:行号 0
在 LiteDB.Engine.LiteEngine.UpdateMany(String collection, BsonExpression transform, BsonExpression predicate) 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\ConnectionForm.cs:行号 0
在 LiteDB.SqlParser.ParseUpdate() 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\ConnectionForm.cs:行号 0
在 LiteDB.SqlParser.Execute() 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\ConnectionForm.cs:行号 0
在 LiteDB.LiteDatabase.Execute(TextReader commandReader, BsonDocument parameters) 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\ConnectionForm.cs:行号 0
在 LiteDB.Studio.MainForm.CreateThread(TaskData task) 位置 C:\Users\DELL\Downloads\LiteDB.Studio-master\LiteDB.Studio\Forms\MainForm.cs:行号 330

修护后的文件,有时候出现查询可以,修改不行。

 

 

4、LiteDB.LiteException: pages in memory store must be non-shared

 

LiteDB.LiteException: pages in memory store must be non-shared

错误解释:

LiteDB 是一个基于 .NET 的轻量级 NoSQL 数据库。LiteException 是 LiteDB 在运行时抛出的异常类型。这个特定的异常 LiteDB.LiteException: pages in memory store must be non-shared 指出在使用 LiteDB 的内存存储时,页面必须是非共享的。

问题通常发生在尝试在多个线程或上下文中使用同一个内存数据库实例时,因为 LiteDB 要求每个数据库实例都有其自己的内存页面存储。如果页面是共享的,可能会导致数据损坏、并发冲突等问题。

解决方法:

确保每次你创建一个新的数据库实例时,都使用一个新的数据库引擎实例。如果你在多线程环境下工作,请考虑使用线程本地存储(Thread Local Storage, TLS)来为每个线程提供独立的数据库引擎实例。

  1. 避免在多个线程间共享数据库实例。

  2. 如果需要在多个上下文中访问数据库,请确保每次都创建一个新的数据库实例。

  3. 如果使用 DI 容器(如 ASP.NET Core 的依赖注入),请确保每个请求都获得一个新的数据库实例。

// 错误的做法,可能在多线程环境下共享数据库实例
var db = new LiteDatabase("memory:");
 
// 正确的做法,为每个线程提供独立的数据库实例
ThreadLocal<LiteDatabase> dbs = new ThreadLocal<LiteDatabase>(() => new LiteDatabase("memory:"));
LiteDatabase db = dbs.Value;

使用 ThreadLocal<T> 可以确保每个线程都有自己的数据库实例。这样做可以避免在多线程环境中出现的任何并发问题。

 

 

erwa.cn

二娃备忘

 

 

 

posted @ 2023-10-14 09:16  二娃网  阅读(395)  评论(2编辑  收藏  举报
www.erwa.cn 二娃备忘