在.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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM