0
votes

I've created simple Windows 10 UWP app. When I'm creating pack in debug mode and install it, everything is alright. But when I run it in Release mode, It fails.

I assume the problem is with my sqlite database. Because when I run it in debug mode the database file is copied to local folder and has his size (17KB). But when I run it in release mode, the size of file is 0 KB.

I have set my database file to:

"Build action: Content"  
"Copy to Output folder: Always"

What could be a problem?

3
I can't reproduce your issue. The setting of your database file and the code you've posted are right. If you still have the problem then please share a minimal reproducible example so that we can reproduce it.Jay Zuo
Hi, thanks for suggestions. I did it (minimize my project) and miracle. This function to check database works in release mode too. But still doesn't know why it doesn't work in whole project. Did you try build my project or You only checked code?user3688227
Sorry, It seems not working. My mistake. I've checked with already created file in local folder. That I thought it works. So I minimalized project. Problem is with 2 function. On 'root' page I execute checkDataBaseConnection() to create database file if not exist. When I debug, I don't know why after calling GetFileFromApplicationUriAsync(uri) the app moves me to LoadChartContents() function, but then, the database is not created yet, so error appears.This behaviour not appear in debug mode. [link]drive.google.com/open?id=0B5ZmP3NVyVJkTnNVc19LYmthNTQuser3688227

3 Answers

1
votes

I've tested your latest minimized project. The problem here is that the checkDataBaseConnection method is a an async method and in your code you didn't wait for it to complete. So it's possible that when LoadChartContents method is executed, the database file has not been copied to LocalFolder. Thus, an error will occur in LoadChartContents method.

To solve this problem, I'd suggest you wait for the checkDataBaseConnection method and navigate to "main" page only when the database exists.

For example, we can change checkDataBaseConnection method like following:

public static async Task<bool> checkDataBaseConnection()
{
    if (null == await ApplicationData.Current.LocalFolder.TryGetItemAsync("sale.db"))
    {
        StorageFile databaseFile = await Package.Current.InstalledLocation.GetFileAsync("sale.db");
        await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder, "sale.db", NameCollisionOption.ReplaceExisting);
    }

    return true;
}

And in "root" page, take advantage of OnNavigatedTo method like:

public root()
{
    this.InitializeComponent();

    PassedData.passSplit = MySplitView;

    SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
}

protected override async void OnNavigatedTo(NavigationEventArgs e)
{
    var result = await myDatabase.checkDataBaseConnection();
    if (result)
    {
        MyFrame.Navigate(typeof(main1));
    }
}
0
votes

Ok, I didn't know that I can easy debug in release mode. So I know now where is the problem

I have this piece of code in function which check database:

var uri = new Uri("ms-appx:///sale.db");
var file = await StorageFile.GetFileFromApplicationUriAsync(uri);

Application crash on GetFileFromApplicationUriAsync(). In debug mode it'works fine.

0
votes

It looks like your problem is linked to properties of your Database file.

Try next steps:

  1. On Visual Studio right click on your Database file in Solution Explorer and select last item called "Properties"
  2. Check 2 properties "Build Action" and "Copy to Output Directory". Based on your requirements - you can configure this two properties as you want.
  3. I think configuration with: "Build Action" = "Content" and "Copy to Output Directory" = "Copy always" should resolve your situation.

Example

For more details you can check file properties on MSDN

Hope it will help you.

UPD:

I noticed that you already applied such actions. I think you have also a problem with access to file.

Try to use next code to access to your file:

var file = await StorageFile.GetFileFromPathAsync(Path.Combine(Package.Current.InstalledLocation.Path, "sale.db"));