简体   繁体   中英

Why is it not possible to use Sqlite in Blazor WebAssembly?

For a platform solution, built with blazor wasm, I'm searching for a light weight storage solution, that is capable of storing big datasets on client side. We came up with the idea of using Sqlite. I literally couldn't find any information about doing so, expect this Stackoverflow question from today, which mentions that it is not possible. Any explanations on this?

Thanks a lot!

As of .NET 6, you can use include native dependencies in Blazor WebAssembly, one example in fact being SQLite. See example code here: https://github.com/SteveSandersonMS/BlazeOrbital/blob/6b5f7892afbdc96871c974eb2d30454df4febb2c/BlazeOrbital/ManufacturingHub/Properties/NativeMethods.cs#L6

Your Blazor WebAssembly C# code still runs in the sandbox of the browser, that means it is not allowed to open files on the local drive.

Blazor WebAssembly has the same access to the machine as any regular website.

Even if someone was to port SQLite to WebAssembly you would not be able to open a database file.

For storage on the client computer you are limited to Local Storage, it is limited to 5 MB (might be different per browser brand) and can only contain strings. But it is not a reliable option as the data will be removed when the users clears the cache, browser history etc..

The only option you have is storing data on the server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM