wsk3q

导航

在.net core 3.1项目中使用Sqlite

由于项目需要使用Sqlite, 所以安装了一些Sqlite库。

刚开始用的是 Microsoft.Data.Sqlite.Core 6.0.0 ,但在new SqliteConnection 时抛出异常。
Unhandled exception. System.TypeInitializationException: The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception.
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Data.Sqlite.Utilities.ApplicationDataHelper.GetFolderPath(String propertyName)
   at Microsoft.Data.Sqlite.Utilities.ApplicationDataHelper.get_LocalFolderPath()
   at Microsoft.Data.Sqlite.Utilities.BundleInitializer.Initialize()
   at Microsoft.Data.Sqlite.SqliteConnection..cctor()

 

不知道怎么解决,google了一下有人说用旧版没问题。于是,换成了上一个版本:5.0.12

//使用 Microsoft.Data.Sqlite.Core 5.0.12,在new 的时候不异常,但open()时异常:
System.Exception: 'You need to call SQLitePCL.raw.SetProvider().  If you are using a bundle package, this is done by calling SQLitePCL.Batteries.Init().'
还缺了个库,再安装 SQLitePCLRaw.bundle_e_sqlite3 就好了,问题解决。

 

==========================================================================
另外,记得五年前,直接使用C编译的sqlite3.dll, 外加一个C#接口层,只需要两个dll.
现在使用这些包,硬盘就非常遭罪了,随便都超过3个dll!

//microsoft:  SqliteConnection
Microsoft.Data.Sqlite.dll
SQLitePCLRaw.batteries_v2.dll
SQLitePCLRaw.core.dll
SQLitePCLRaw.provider.e_sqlite3.dll
runtimes目录
    ├─alpine-x64
    │  └─native
    ├─linux-arm
    │  └─native
    ├─linux-arm64
    │  └─native
    ├─linux-armel
    │  └─native
    ├─linux-mips64
    │  └─native
    ├─linux-musl-x64
    │  └─native
    ├─linux-s390x
    │  └─native
    ├─linux-x64
    │  └─native
    ├─linux-x86
    │  └─native
    ├─osx-arm64
    │  └─native
    ├─osx-x64
    │  └─native
    ├─win-arm
    │  └─native
    ├─win-arm64
    │  └─native
    ├─win-x64
    │  └─native
    └─win-x86
        └─native


//官方:      SQLiteConnection
//官方依赖:
EntityFramework.dll
EntityFramework.SqlServer.dll
Microsoft.Win32.SystemEvents.dll
System.CodeDom.dll
System.Configuration.ConfigurationManager.dll
System.Data.SqlClient.dll
System.Data.SQLite.dll
System.Data.SQLite.EF6.dll
System.Drawing.Common.dll
System.Security.Cryptography.ProtectedData.dll
System.Security.Permissions.dll
System.Windows.Extensions.dll

runtimes目录
├─linux-x64
│  └─native
├─osx-x64
│  └─native
├─unix
│  └─lib
│      ├─netcoreapp2.1
│      └─netcoreapp3.0
├─win
│  └─lib
│      ├─netcoreapp2.1
│      ├─netcoreapp3.0
│      └─netstandard2.0
├─win-arm64
│  └─native
├─win-x64
│  └─native
└─win-x86
    └─native

 

posted on 2021-11-12 16:56  wsk3q  阅读(1564)  评论(0编辑  收藏  举报