Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 302
xport Avatar asked Dec 16 '25 19:12

xport


1 Answers

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"
like image 155
Etienne Charland Avatar answered Dec 19 '25 12:12

Etienne Charland