SQLite基础(七)全面、详细、权威介绍NeGet包管理:对SQLite添加几个常用的程序包Pacakage

目录

第一章、简介

第二章、安装SQLite v1.0.109.2版本

2.1、找到管理界面 

2.2、安装指定包源

2.3、选择指定包源

2.4、窗口显示SQLite v1.0.109.2版本

2.5、选中、安装 

2.6、安装成功

2.7、System.Data.SQLite、System.Data.SQLite.EF6、System.Data.SQLite.Linq版本分析

 第三章、下载完整的包安装

3.1、获取完整包

3.2、添加、选中、浏览指定包源: 

3.3、点击安装:

3.4、程序的运行结果

3.5、Bug问题分析

3.6、EF映射关系导致数据库丢失、生成新的数据库。

第四章、总结


第一章、简介

        SQLite虽然更新到了1.0.111.0版本,有时候会遇到图1.1所示的问题:版本冲突问题。

       于是,我们为了解决版本冲突问题,不得不安装旧的版本包,比如安装SQLite v1.0.109.2、安装SQLite v1.0.109.0等等。那么先看第二章,我们如何来安装SQLite v1.0.109.2版本。

第二章、安装SQLite v1.0.109.2版本

2.1、找到管理界面 

2.2、安装指定包源

 

2.3、选择指定包源

 2.4、窗口显示SQLite v1.0.109.2版本

2.5、选中、安装 

2.6、安装成功

         安装成功后,会看到“引用”节点上,出现几个DLL文件:System.Data.SQLite、System.Data.SQLite.EF6、System.Data.SQLite.Linq

2.7、System.Data.SQLite、System.Data.SQLite.EF6、System.Data.SQLite.Linq版本分析

         最后发现,System.Data.SQLite、System.Data.SQLite.EF6、System.Data.SQLite.Linq这几个版本还是1.0.111.0版本。这几个运行后,会提示这样的异常

SeriesInfoDal.cs::SearchSeriesInfo()——  查找序列表发生错误:System.Data.Entity.Core.EntityCommandExecutionException: 执行命令定义时出错。有关详细信息,请参阅内部异常。 ---> System.Data.SQLite.SQLiteException: SQL logic error
no such table: SeriesInfo
   在 System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, String& strRemain)
   在 System.Data.SQLite.SQLiteCommand.BuildNextCommand()
   在 System.Data.SQLite.SQLiteDataReader.NextResult()
   在 System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
   在 System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
   在 System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   在 System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
   在 System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   --- 内部异常堆栈跟踪的结尾 ---
   在 System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   在 System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
   在 System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   在 System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5()
   在 System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   在 System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
   在 System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
   在 System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   在 System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   在 KeenRayLargePC.PadDataAcessLayer.SeriesInfoDal.SearchSeriesInfo(Expression`1 whereLambda) 位置 D:\keenray6.2\trunk\code\iPads\PadDataAcessLayer\SeriesInfoDal.cs:行号 115

   这类的异常问题,可以参考

https://stackoverflow.com/questions/54044353/sql-logic-error-no-such-table-porting-xaf-standard-security-to-sqlite

https://www.cnblogs.com/wolf-sun/p/6957702.html

  • 一个解决第二章问题的思路,你也可以把SQLite关联的四个包,弄成同一个版本1.0.111。NeGet的管理窗口,默认可以安装最新版的四个包。但是这种思路无法解决我的问题,我的问题和这篇博客的的问题是一样的http://www.bubuko.com/infodetail-347837.html
  • 而我另一个解决思路(第三章),要把SQLite关联的四个包,弄成同一个版本1.0.109。

 第三章、下载完整的包安装

3.1、获取完整包

我说的完整包,是指你想要的版本的四个包,可以都是1.0.111,也可以都是1.0.109 。官网获取或其他项目拷贝过来。

我说的完整包,是指你想要的版本的四个包,可以都是1.0.111,也可以都是1.0.109 。官网获取或其他项目拷贝过来。

我说的完整包,是指你想要的版本的四个包,可以都是1.0.111,也可以都是1.0.109 。官网获取或其他项目拷贝过来。

        NeGet包的后缀名:

        在我其他的工程项目,下面的几个包版本,是可行的,SQLite数据库、数据表没有异常:

  • System.Data.SQLite.1.0.109.2
  • System.Data.SQLite.Core.1.0.109.2
  • System.Data.SQLite.EF6.1.0.109.0
  • System.Data.SQLite.Linq.1.0.109.0

      由于第二章中我只有包System.Data.SQLite.1.0.109.2,没有System.Data.SQLite.Core.1.0.109.2、System.Data.SQLite.EF6.1.0.109.0、System.Data.SQLite.Linq.1.0.109.0。

      现在,我把这几包补充完毕,放到我的指定目录下:

                                                                                      图3-1 

3.2、添加、选中、浏览指定包源: 

                                                                                      图3-2 

浏览后、点击更新:

                                                                                        图3-3 

重复步骤,把另外的两个包源,也添加进来:

                                                                                     图3-4 

3.3、点击安装:

                                                                                         图3-5 

3.4、程序的运行结果

还是存在这样的Bug:

SeriesInfoDal.cs::SearchSeriesInfo()——  查找序列表发生错误:System.Data.Entity.Core.EntityCommandExecutionException: 执行命令定义时出错。有关详细信息,请参阅内部异常。 ---> System.Data.SQLite.SQLiteException: SQL logic error
no such table: SeriesInfo
   在 System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, String& strRemain)
   在 System.Data.SQLite.SQLiteCommand.BuildNextCommand()
   在 System.Data.SQLite.SQLiteDataReader.NextResult()
   在 System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
   在 System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
   在 System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   在 System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
   在 System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   --- 内部异常堆栈跟踪的结尾 ---
   在 System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   在 System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
   在 System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   在 System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5()
   在 System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   在 System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
   在 System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
   在 System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   在 System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   在 KeenRayLargePC.PadDataAcessLayer.SeriesInfoDal.SearchSeriesInfo(Expression`1 whereLambda) 位置 D:\keenray6.2\trunk\code\iPads\PadDataAcessLayer\SeriesInfoDal.cs:行号 115

3.5、Bug问题分析

        无论是第二章,还是第三章,我们已经完整的添加了SQLite的四个包,单还是遇到同样的问题。特别是第三中同版本1.0.109的四个包,我在其他项目中是可以用的,也没有遇到这样的问题。

       这样我不得不怀疑,异常问题中,没有找到数据表的原因,可能是这个数据库被加密了。

3.6、EF映射关系导致数据库丢失、生成新的数据库。

        最后,我的问题定位在数据库文件上,原来之前多次映射,导致数据库名字发生了变化,这是非常关键的地方,这也是我之前发生过一次数据库文件丢失,现在又发生了一次错误的映射关系。因此我们需要注意:

  • 数据库文件放到指定的A目录,并与指定工程B目录,建立EF映射关系——这样才不置于经常发生EF映射错误。
  • 如图3-6,如果你把映射表Pad.edmx删除,再重新建立一个映射文件Padddddd.edmx(数据库文件A目录不变,B目录不变)——这杨会导致文件生成一个空的Padddddd.db3文件,就会导致找不到数据表,发生SQL logic error no such table:XXXXX的错误。但是原来的Pad..db3文件还在
  • 如果你把映射表Pad.edmx删除,再重新建立一个映射文件Pad.edmx(数据库文件A目录不变,B目录不变)——这时候,有可能导致最新的数据库文件会覆盖旧的数据库文件,导致数据表丢失(因此我丢失过一次,具体是不是这样,大家可以尝试一次,注意备份数据库)。原来的Pad..db3文件已经被覆盖,不存在了

                                             

                                                                             图3-6

第四章、总结

  • 注意程序集的应用——有时候,我们直接引用图4-1所示的几个DLL,并不能解决数据库的一些错误。这时候,我们可以通过NeGet包管理,来建议这几个DLL的依赖关系;那么,就可以正常的使用SQLite数据库了。
  • 依赖项行为——安装第一个包SQLite,会自动关联安装其他的三个包。
  • 注意备份数据库。
  • 注意不要经常修改EF映射关系。
  • 注意版本不能冲突——要么全是旧的版本,要是全是最新版。
  • 置于本文为什么阐述一定要使用SQLite 109的版本,是因为我记得111的版本不能满足我某个方面的功能需求。具体是啥功能,我忘记了,不好意思啦。

 

                      

                                                                                   图4-1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我爱AI

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值