英文:
How to find .NET Maui sqlite DB file
问题
我有一个.NET Maui Blazor应用程序,并通过Entity Framework Core配置了SQLite存储:
builder.UseSqlite("Data Source=app.db")
一切都正常工作。出于调试目的,我想从数据库资源管理器中访问SQLite数据库文件。我发现当我以Windows目标的调试模式启动应用程序时,文件存储在以下位置:
c:\Users\<username>\AppData\Local\Packages\5A71F6B4-07D1-4042-BC1C-C1FD1963A030_9zz4h110yvjzm\LocalState\app.db
。
这不是开发者友好的体验。如何从.NET Maui Blazor应用程序外部"挂载"数据库文件,或者在调试主机机器上指定文件路径,以使其不是随机的?
英文:
I have a .NET Maui Blazor App and configured SQLite storage via Entity Framework Core:
builder.UseSqlite($"Data Source=app.db")
Everything is working fine. For debugging purposes, I want to access the SQLite database file from a database explorer. I found that the file is stored at this location, when I start the app in Debug mode for Windows target.
c:\Users\<username>\AppData\Local\Packages\5A71F6B4-07D1-4042-BC1C-C1FD1963A030_9zz4h110yvjzm\LocalState\app.db
.
This is poor developer experience.
How can I "mount" the database file from outside a .NET Maui Blazor app or specify the file path on the debugging host machine so that it's not random?
答案1
得分: 4
生成的随机文件夹名称是 {GUID}_{hash}
,是随机生成的。
如果您想指定数据库的路径并去掉随机数部分,您可以尝试以下方法,该方法位于 c:\Users\<username>\AppData\Local\
目录下:
string dataSource = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "app.db");
builder.UseSqlite($"Data Source={dataSource}");
或者您可以像Dimi建议的那样使用绝对路径,位于 C:
中,
builder.UseSqlite(@"Data Source=C:\app.db");
英文:
The generated randomly file folder is {GUID}_{hash}
which is generated randomly.
If you want to specify the path that the db located and remove the randomly number, you can try to use below which is located in c:\Users\<username>\AppData\Local\
:
string dataSource = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "app.db");
builder.UseSqlite($"Data Source={dataSource}");
Or you can use absolute path located in C:
as Dimi suggested,
builder.UseSqlite(@"Data Source=C:\app.db");
答案2
得分: 2
你可以通过在连接字符串中提供绝对路径来指定数据库位置:
options.UseSqlite("Data Source=C:\your\path\app.db");
英文:
You can specify the database location by providing an absolute path in the connection string:
options.UseSqlite("Data Source=C:\your\path\app.db");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论