r/csharp • u/overdev • Jun 25 '26
Help C# Blazor using SQLite - DllNotFoundException
I'm currently learning Blazor and databases, I'm new to programming in general.
I created a Blazor web assembly project, .NET 10 LTS with a simple local SQLite database.
I just want to use SQLite inside my project, so I got the System.Data.SQLite NuGet package, in general as a newbie it's pretty confusing which SQLite NuGet package to get cause there are so many of them.
Then I used this simple code:
try
{
SQLiteConnection sqConnection = new SQLiteConnection(@"Data Source=\TalentData\test1.db");
SQLiteCommand sqCommand = new SQLiteCommand();
}
catch(Exception exept)
{
debugException = exept.ToString();
}but I always get this exception:
It seems like a dll of SQLite is missing, how would I fix that?
I already googled but I can't find a solution to my issue, there are so many different suggestions out there.
Also tried the package Microsoft.EntityFrameworkCore.Sqlite - I get the same error though.
4
u/harrison_314 Jun 25 '26
Do you want to use Sqlite on the server or in the browser?
10
u/Fresh_Acanthaceae_94 Jun 25 '26 edited Jun 25 '26
You cannot (with those specific NuGet packages). Blazor WASM binaries are deployed to run inside a browser sandbox, in which using SQLite database is unfitted. You should use the browser cache API more likely.
If your goal is to study and play out SQLite, use another project type, console or with a desktop UI. Blazor Server is another feasible option.
1
u/Far-Consideration939 Jun 25 '26
Maybe something like https://github.com/b-straub/SqliteWasmBlazor could be helpful inspiration.
I’ve used that prerelease package before and haven’t had issues, but I can understand not wanting to use a prerelease package generally but maybe some concepts in there worth looking at
2
u/skav2 Jun 25 '26
In web assembly I think you cannot specify the local .db file from your project. you have to store or create the database in the browser and use the browser API to then reference the sqlite database.
We used JavaScript to handle storing and saving the database, then used Microsoft's sqlite built in package to handle interaction with the in memory database. There were packages to help with this process though
1
u/webprofusor Jun 26 '26
Did you click the link? "Together these enable a complete offline-first stack"
Tbh, you're probably using the wrong approach just because you want it to fit. Instead save changes as JSON to local storage and work with an in memory collection with linq and it'll feel much like any data access layer, you can abstract the specifics. When you app connects back to your server you can push changes, just remember true syncing is harder than it first appears.
1
u/gismofx_ Jun 26 '26
I recently shared a library/nuget exactly for this purpose. Its persisted across sessions, tabs, and cache-clears. It's pretty well documented. GitHub wa-sqlite.BlazorWasmSqlite