DEV Community

Cover image for Using SQLite in .NET Core Azure Web App
Halldor Stefansson
Halldor Stefansson

Posted on • Updated on • Originally published at halldorstefans.com

Using SQLite in .NET Core Azure Web App

Photo by Verne Ho on Unsplash

Originally published on my blog at halldorstefans.com on 27. April 2020

This is going to be a short demonstration on 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 your 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 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:

    1. Right-click the publish folder and select Deploy to Web App...
    2. Select the subscription I want to use to create the Web App
    3. Select the Web App I want to deploy to
    4. 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. For weekly updates from me, you can sign up to my newsletter.

Top comments (0)