Deploy a .NET Core App With SQLite to Azure

A short demonstration of how I managed to utilise SQLite for a simple .NET Core API hosted in an Azure Web App.

Deploy a .NET Core App With SQLite to Azure

Photo by Verne Ho on Unsplash

This is going to be a short demonstration of how I use SQLite in my API hosted in Azure.

Few assumptions I'm making:

  • Your application is finished and you're ready to deploy to Azure
  • Your database is not big

This demonstration is based on this tutorial from Microsoft

1. Create a Release Package

Open your terminal and make sure you're in the right folder.
In my case, that was at the same level as the '.sln' file was.
If you don't have a '.sln' file, maybe you have a '.csproj' file.

Run the following command to create a release package in a subfolder called publish:

dotnet publish -c Release -o ./publish

2. Copy database to the new folder

This step is kinda the only difference versus the Microsoft tutorial :)

Copy-Paste your database, for example 'my.db', into the newly created 'publish' folder.

3. Publish to Azure

There are a few ways to publish to Azure.

I usually start in the portal and create what I need there.

Then, since I'm using Visual Studio Code and have the Azure App Service extension, I do the following:

  • Right-click the publish folder and select Deploy to Web App...
  • Select the subscription I want to use to create the Web App
  • Select the Web App I want to deploy to
  • Hit 'deploy' in the pop-up window

4. Set Connection String

Once the app has been deployed to Azure, you set your connection string in the Azure App Service.

You can find the setting under Settings -> Configuration -> Connection strings.

There you create a new connection string, for example:

Name SQLiteConnection
Value Data Source=mydb.db;
Type Custom

5. Ready

Your application will now use the database in the publish folder that was deployed to Azure.

Hope this helped.

If you want to migrate from SQLite to Azure SQL Database, you can use this tutorial for that.
I did try to do this, but I was in a hurry and it failed. Might try again later.

Thank you for reading.