C# local database

Ward Horsfall 106 Reputation points
2022-10-10T13:20:39.493+00:00

Hi
I want to write.net WinUi app and want to know if I want to create a local database SQL like is there a standard I should use.

For example Microsoft Access use to be to goto standard - what is the correct standard now I should use now.

Btw the database only needs to have local access only.

Thanks

Ward

Developer technologies C#
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2022-10-10T14:00:46.72+00:00

    It depends upon your needs. If you need a simple database then you could use Access. If you need something more "SQL" like then use SQL Express. But these require external software installations. Of course there are other databases as well including MySQL you could use.

    If you need something embedded then use any # of embedded SQL products like Sqlite or equivalent.

    For local development only then Visual Studio ships with a LocalDB instance already installed. You technically can use this on non-dev machines as installers provide it as an option but it is really just a stripped down version of SQL Express. But it isn't patched or anything so it would introduce security risks on client machines. It would be better to use SQL Express if you wanted to go that route.

    Of course you don't necessarily need a local DB at all. If it fits your needs you could also consider using a cloud-based DB and host the DB in the cloud somewhere. It depends on what you intend to do with it.


  2. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2022-10-10T15:49:39.907+00:00

    It’s a local database for the app, then SQLite is the common solution.

    0 comments No comments

  3. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2022-10-10T15:52:15.413+00:00

    No matter which database is selected, consider using Entity Framework Core. It's Microsoft's standard followed by using a data provider or another alternate is dapper.

    The nice thing about EF Core is you can use it in Windows Forms, WPF, MAUI, ASP.NET Core along with if you decide to change databases less changes are required than a data provider.

    If the project is for you along, consider @Michael Taylor recommendation of LocalDb which if later you decide to go with SQL-Express its a matter of recreating the database in SQL-Express.

    For EF Core, take a look at my GitHub repository for tips (not fully done yet but all code works) and a simple Razor Pages demo in the repository.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.