Display Name
Display Name

Reputation: 15101

Where is the Sqlite database saved for asp.net core MVC 2.2?

I create an asp.net core mvc 2.2 application with

options.UseSqlite("Data Source=test.db")

Important note: VS2017 must be launched with Administrative Privilege, otherwise database cannot be created. It is specific to Asp.net core 2.2, the previous one has no such a problem.

Question

Where is the sqlite database saved? I have searched for but I got nothing.

Note: As a comparison, Asp.net core 2.1 saves the sqlite database in the project folder.

Upvotes: 3

Views: 3122

Answers (1)

Etienne Charland
Etienne Charland

Reputation: 4024

Control where it is stored the easy way

var connString = Configuration.GetConnectionString("MyDB").Replace("~", _env.ContentRootPath);
services.AddDbContext<RemoteHealingTechContext>(options => options.UseSqlite(connString));

Grabbing _env in the constructor

public Startup(IConfiguration configuration, IHostingEnvironment env)
{
    Configuration = configuration;
    _env = env;
}

Then you can use a connection string that looks like this

"DataSource=~\\App_Data\\MyDB.db"

Upvotes: 3

Related Questions