Matteo
Matteo

Reputation: 252

ASP.Net Core Sqlite in Azure

I have a ASP.NET Core Web Application using a SQlite database. This works perfect, but now I want to host it in azure. Where should i put my *.db file? I suppose the wwwroot folder is not the best place as it can be browsable!

There used to be the App_Data folder for this. Where should these kind of files go in ASP.NET Core?

Thanks for the hints...

Upvotes: 3

Views: 2533

Answers (2)

Temi Lajumoke
Temi Lajumoke

Reputation: 2400

The easiest way to do this would be to upload the database right in your root directory. That means the directory where you have your {WebsiteName.dill} or WebApplication.dll by default. For Azure, this would be your D:\home\site\wwwroot directory (note that this is not the wwwroot folder for static files in your application, but rather, the root folder in azure also named wwwroot). Then you would connect to this database with a connection string in your appsettings.Production.json file like so.

"ConnectionStrings": {
    "DefaultConnection": "Data Source=<DATABASE_NAME>.db"
  }

. That should do the trick.

Upvotes: 0

Matteo
Matteo

Reputation: 252

So what I found out is that if you use the following setting:

"ConnectionStrings": {
   "DefaultConnection": "Data Source=.\\DbName.db" 
}

The database file will be automatically placed in the root folder of the Web Application on Azure and not as I thought into the wwwroot. So this works perfectly for me and brings the advantage that no directory exist check has to be done before creating the database file.

Upvotes: 4

Related Questions