Reputation: 531
i'd like to create a simple azure web app, which stores data within the folder where it is deployed (..\wwwroot\
).
I downloaded the provided sample code from "myapp".azurewebsites.net but there EntityFramework is used. Is it possible to configure EF to use SQLite or do I need to implement my own SQLite Provider? (...using the PCL version from https://www.nuget.org/packages/sqlite-net-pcl/
Can someone recommend me any samples? I didn't find suitable snippets for SQLite on Azure.
This is my code so far:
public class DataService
{
private static string sqliteFilename = "myDbName.sqlite";
private static SQLiteConnection dbConnection;
public static bool Initialize()
{
Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"\App_Data\"));
string path = Path.Combine(HttpContext.Current.Server.MapPath(@"\App_Data\"), sqliteFilename);
dbConnection = new SQLiteConnection(path);
dbConnection.CreateTable<Category>();
dbConnection.CreateTable<User>();
return true;
}
}
I get an error, that doesn't tell me much about it...
The type initializer for 'SQLite.SQLiteConnection' threw an exception
Upvotes: 3
Views: 3148
Reputation: 16126
Files of a deployment package are uploaded into the Azure Runtime environment, and persisted in the directory d:\home. These files are persistent and are shared between multiple instances of the site. In the Free and Shared tiers of the Web App the persistent storage limit is 1 GB, while Basic and Standard tiers get 10GB and 50GB.
So instead of creating the sqlite file in code; pre-create it, and upload it with as a file among the set of deployed files. Use kudu to find the actual path to the file and reference that in your code.
Ref: https://github.com/projectkudu/kudu/wiki/Azure-runtime-environment#file-system
The drawback of this approach is that the database file would be replaced every time a deployment is performed.
Upvotes: 2