Jump to content
CarloM

Where to put SQLite/MDB database in UWP app

Recommended Posts

Hi,

 

I am trying to generate an appx with Delphi Sydney, but I dont know where deploy database file, reports files,... for read/write.

 

When I compile for Mac use this remote path "Contents\Resources\StartUp\" for DB files, reports,.... 

 

But on Windows I don´t know if exists especial folders.

 

Thank you so much

Share this post


Link to post

Hi Lars,

 

the question is where I specify data folders under deployment window

 

see image for clarification

 

 

ss.png

Share this post


Link to post

Does

%APPDATA%\YourAppName\ 

work?

It resolves to C:\Users\<username>\AppData\Roaming

 

Alternatively,
%LOCALAPPDATA% C:\Users\<username>\AppData\Local
 

Share this post


Link to post

It does not work, It creates a %Appdata% folder.

 

I don´t understand it, if I need to use a local MS access DB, where is the correct location path for deploy this file ?

 

Share this post


Link to post

Is the DB supposed to specific for the current user, or do you want a single DB for all users on the machine?

Share this post


Link to post
2 minutes ago, Lars Fosdal said:

Where does it create that folder?

 

Yes, Create a folder named %APPDATA%. Not resolve

Share this post


Link to post
2 minutes ago, Lars Fosdal said:

Is the DB supposed to specific for the current user, or do you want a single DB for all users on the machine?

at first time, for current user

Share this post


Link to post
2 minutes ago, CarloM said:

Yes, Create a folder named %APPDATA%. Not resolve

Where is that folder created?

10 minutes ago, CarloM said:

It does not work, It creates a %Appdata% folder.

 

When it creates a folder named %APPDATA% - Where does it create it?
C:\users\username\%APPDATA% ?

C:\%APPDATA% ?


Where is it created?
 

Share this post


Link to post

If you name it

.\YourAppFolder\

Where is that folder created in the current user's file system?

Share this post


Link to post
Just now, Lars Fosdal said:

If you name it


.\YourAppFolder\

Where is that folder created in the current user's file system?

C:\Program Files\WindowsApps\MYAPPNAME_1.0.0.0_x86__ay3z6v4jhrvfp

 

 

Share this post


Link to post

Which looks like a shared folder - unless that part on the end is a user specific key.

If you install it with a different user - is a new folder C:\Program Files\WindowsApps\MYAPPNAME_1.0.0.0_x86__?????? created, or is the same folder used?

 

Looking at http://docwiki.embarcadero.com/RADStudio/Sydney/en/Deployment_Manager,

all the examples simply uses .\ - so perhaps that is sufficient.

Share this post


Link to post

I honestly don't think the deployment manager is the right tool for this. It's intended to bundle the sqlite template with your app, but not initialize "first run" scenarios.

 

The user files belong in %AppData% and Windows takes care of virtualizing this per user. So all you have to do is, at runtime, take your local .sqlite file and copy it to %Appdata%\... if it's not already there.

Share this post


Link to post

On the other hand, APPX apps are supposed to be sandboxed - hence moving a file to a different part of the system might not be a good idea?

I could be wrong about this, though.

Share this post


Link to post
18 minutes ago, Der schöne Günther said:

I honestly don't think the deployment manager is the right tool for this. It's intended to bundle the sqlite template with your app, but not initialize "first run" scenarios.

 

The user files belong in %AppData% and Windows takes care of virtualizing this per user. So all you have to do is, at runtime, take your local .sqlite file and copy it to %Appdata%\... if it's not already there.

But, copy manually files on first run ? 

 

Share this post


Link to post
7 minutes ago, Lars Fosdal said:

hence moving a file to a different part of the system might not be a good idea?

I don't quite understand what you mean with "different part of the system". Every packaged app gets its own view of the registry and the file system. Here is a good summary:

https://docs.microsoft.com/en-us/windows/msix/desktop/desktop-to-uwp-behind-the-scenes

  • Like 1

Share this post


Link to post

Different part - as in Outside the sand box - but it seems the file system is fully virtualized.

 

A bit odd that you cannot specify %APPDATA% in the deployment system, since that actually is the appropriate path.

 

Write under AppData Windows 10, version 1903 and later: New files and folders created under the following directories are redirected to a per-user, per-package private location:
  • Local
  • Local\Microsoft
  • Roaming
  • Roaming\Microsoft
  • Roaming\Microsoft\Windows\Start Menu\Programs
In response to a file open command, the OS will open the file from the per-user, per-package location first. If this location doesn't exist, the OS will attempt to open the file from the real AppData location. If the file is opened from the real AppData location, no virtualization for that file occurs. File deletes under AppData are allowed if user has permissions.

 

Windows 10, version 1809 and earlier: Copy-on-written to a per-user, per-app location.

AppData is typically C:\Users\user_name\AppData.

Share this post


Link to post

I can't believe the installer can't copy the files directly to the user folder with read and write permissions

Share this post


Link to post

A deployment manager deploys files. It's not an installer.

 

8 minutes ago, Lars Fosdal said:

A bit odd that you cannot specify %APPDATA% in the deployment system

Maybe they will add something like this once RAD Studio will also support MSIX.

Share this post


Link to post

As I understand... I need to copy manually files to another folder ?

I'm surprised...

Share this post


Link to post

I never tested it, but if you open the System.StartUpCopy.pas you will see that in Windows, always when your program run, it will try to copy files from ExtractFilePath(ParamStr(0)) + '\StartUp\' to TPath.GetHomePath (in windows it is AppData\Roaming\).

 

So, you can try to put in Deployment remote path: .\StartUp\yourapp\database.sqlite3

And to load the database in runtime you can try to use TPath.GetHomePath + '\yourapp\database.sqlite3'

Edited by vfbb
  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×