Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create database from a Windows Phone signed app fails #25

Closed
eugenioestrada opened this issue May 7, 2014 · 6 comments
Closed

Create database from a Windows Phone signed app fails #25

eugenioestrada opened this issue May 7, 2014 · 6 comments

Comments

@eugenioestrada
Copy link

Hi, I've published an app as a Beta and the app cannot create the database file (in debug mode it works). It seams to be something similar to the exposed in this link: http://developer.nokia.com/community/wiki/How_to_use_SQLite_in_Windows_Phone.

I've tried to copy the database file to included it as content, but I don't find where the file is being created.

The unsigned app works correctly.

@oysteinkrog
Copy link
Owner

Hi, I'm sorry but I have no experience with Windows Phone apps, I don't have any idea why could be.
@ncipollina @micahl @vladstoick Do you guys have any ideas?

@eugenioestrada
Copy link
Author

Thanks you @oysteinkrog! Now my app is working with an xap signed for the Windows Phone Store. Part of the problem was the described on the developers.nokia.com site. (The database file has to be added to the project as content and has to be copied to the Isolated Storage.

        StorageFile dbFile = null;

        try
        {
            // Try to get the 
            dbFile = await StorageFile.GetFileFromPathAsync("PATH");
        }
        catch (FileNotFoundException)
        {
            if (dbFile == null)
            {
                IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();
                using (Stream input = Application.GetResourceStream(new Uri("ASSEMBLY;component/FILENAME", UriKind.Relative)).Stream)
                {
                    using (IsolatedStorageFileStream output = iso.CreateFile("PATH"))
                    {
                        byte[] readBuffer = new byte[4096];
                        int bytesRead = -1;

                        while ((bytesRead = input.Read(readBuffer, 0, readBuffer.Length)) > 0)
                        {
                            output.Write(readBuffer, 0, bytesRead);
                        }
                    }
                }
            }
        }

It can be done it the Application_Launching of the App.xaml.cs file.

The other problem is that only a filename not works in Windows Phone and you should use a path like that:

 string path = Path.Combine(Path.Combine(ApplicationData.Current.LocalFolder.Path, "cache.sqlite"));

I think that you can add that to the documentation, because it's not clear.

@oysteinkrog
Copy link
Owner

Ah, good to hear you got it working.
I'll update the readme:)

@Depechie
Copy link

Depechie commented Jun 4, 2015

Had some similar problems and documented them on my blog... Maybe the pre compiler part could be looked at for the readme too? http://depblog.weblogs.us/2015/01/06/sqlite-net-and-sqlite-net-extensions-with-universal-apps/

@oysteinkrog
Copy link
Owner

Hmm that blog posts seems to confuse the original sqlite-net project and this fork.
I created this fork for PCL support and I've ended up incorporating lots of fixes and features.
What makes everything even more confusing is that the original project also has PCL support now! :P
I've never done much WP development and I've barely event tested that code, it's primarily from contributors.
If anyone has some suggestions for improvements in the readme please send a pull request!

@reader-man
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants