Sqlite load extension documentation could be more detailed
Help us make content visible
Loading of Sqlite extensions is documented on this site: https://docs.microsoft.com/en-us/dotnet/standard/data/sqlite/extensions
An example of the extension loading process is described in this file: https://github.com/dotnet/docs/blob/main/samples/snippets/standard/data/sqlite/ExtensionsSample/Program.cs
But what is unclear is, what Nuget Packages are needed, that the extensions could be found?
The extension I would like to use is Spellfix1. It would be cool, if it could be described, if it is contained in a Nuget packages, or if the manual extension compilation is needed. https://stackoverflow.com/questions/71244785/sqlite-with-spellfix1-extension-used-with-entity-framework-core-crash-on-second
Describe the new article
- the new article would make using Sqlite extensions more easy with C# and .Net Core.
- The article should cover which Nuget packages are needed and what steps has to be done, to use Sqlite extensions like spellfix1.
- The linked Sqlite load extension example code seems overly complicated. Maybe are more intuitive version is possible.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 28cc6540-9c25-7f9c-1bd1-53b375363f34
- Version Independent ID: 8f09d434-7676-75df-9677-fb8cd7d9c9e9
- Content: Extensions - Microsoft.Data.Sqlite
- Content Source: docs/standard/data/sqlite/extensions.md
- Product: dotnet-data
- GitHub Login: @bricelam
- Microsoft Alias: bricelam
The best way to get SQLite extensions is to install them using the OS package manager. For example, APT on Debian-based Linux distros or Homebrew on macOS.
We decided to create a NuGet package to distribute SpatiaLite on Windows since things like Chocolatey, Scoop, and winget aren't widely used and AFAIK don't have any packages for SpatiaLite. As you can see by the sample, there are a lot of hoops we have to jump through to actually get the correct version of mod_spatialite.dll to be on the Path before trying to get SQLite to load it.
My recommendation is to find a simpler solution that works just for your application. For example, if you know your app will only ever run on Windows x64, then just include that DLL in your project and set Copy to Output Directory. If your app is intended to be cross-platform, then things start to get more complicated.
Thank you for your answer! My app targets only Windows, so I guess copying the DLL to the output directory is enough.
First I thought the MSDN documentation for Sqlite could be more detailed, but as you described, it is a more complex subject than previously assumed, especially for users which are targeting multiple OS.
First I downloaded the Sqlite Amalgamation from this url: https://www.sqlite.org/2022/sqlite-amalgamation-3380000.zip Then downloaded the source folder from this url: https://www.sqlite.org/2022/sqlite-src-3380000.zip
After unziping both folders, I have copied the files sqlite3.h, sqlite3.c and sqlite3ext.h from the first folder to
sqlite-src-3380000/ext/misc
from the second folder. Then I have run with Cygwin64 the following command:
gcc -I -g -shared spellfix.c -o spellfix.dll
The spellfix.dll could be created, but it seams rather small with 88 kb.
When I tried to load it, the following error is displayed:
Microsoft.Data.Sqlite.SqliteException: "SQLite Error 1: ' Module not found.
It makes no difference, if a relative or absolute Dll filepath was used.
var connection = new SqliteConnection("Data Source=LoadModuleTest.sqlite;");
connection.Open();
connection.EnableExtensions(true);
connection.LoadExtension(@"spellfix.dll");
connection.Close();
Have you any ideas, what am I missing?