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
-
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
-
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.
-
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:
- 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
-
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 -
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)