Use SQLite instead of SQLServer in Blazor Web App (in .Net 8.0)

I saw this on your web site  (not really related to any control, but I had to pick one to post here)


How do I implement authentication using SQLite in Blazor? (syncfusion.com)


I was wondering if anyone has an example of how to do this for .Net 8.0, as when trying I get errors


I asked the question on Stackoverflow as well


Blazor Web App (.net 8) - switch user authentication to use SQLite instead of SQLServer - Stack Overflow


1 Reply

BH BharatRam Harikrishnan Syncfusion Team December 15, 2023 01:00 PM UTC

Hi Robert,

 

In .NET 8, you can use SQLite by default instead of SQL Server by utilizing the command-line version of creating a project, which includes a SQLite database for Identity:

 

dotnet new blazor --name sample --auth Individual

 

For more details, please refer to the Microsoft documentation: Secure ASP.NET Core server-side Blazor apps | Microsoft Learn.

 

However, as suggested in the following Stack Overflow post: https://stackoverflow.com/a/77644123, in an already created Blazor Web app targeting .NET 8 with Authentication, you can also delete the already created migration files for SQL Server and then follow the steps below to set up SQLite as database:

 

  1. Update the NuGet package: Remove the Microsoft.EntityFrameworkCore.SqlServer NuGet package from the current package manager and add the Microsoft.EntityFrameworkCore.Sqlite package.
  2. Modify the Program.cs file: Change the "options.UseSqlServer" in the Program.cs file to "options.UseSqlite".

 

 

 

  1. Modify the connection string in the AppSettings.json file: Set the connection string to "DataSource=<yourdbname>.db" (pointing to your SQLite database file).
  2. Run the following commands:

add-migration

Update-Database

 

Please try the above and get back us if you need further assistance.


Regards,

Bharat Ram H


Loader.
Up arrow icon