UWP How Packaging APP if I use SqLite - sqlite

I use SQLite in my UWP App.
All work good on my PC in debug mode.
After installation on a W10 Device the APP close itselfs when I try to create a SQLite's Database.
I think it's a write-problem on the device.
Perhaps no write rights?
Where and How can I set it on my package?
Thanks a lot
Daniele Pinai

Right-click your UWP project in the Solution Explorer and choose Add -> Reference....
In the dialog window choose Universal Windows and below select Extensions.
In this list ensure that Visual C++ 2015 Runtime for Universal Windows and SQLite for Universal Windows Platform are checked.
In case you can't find the SQLite for Universal Windows Platform there, you will have to install this extension. You can do this using the Extensions and Updates window in Visual Studio, or by downloading and installing the latest sqlite-uwp- package from the SQLite website.

Related

Unable to load DLL 'sqlite3' - for Windows Universal Mobile

I used Visual Studio 2015 with SP2. I try created Windows Universal app with sqlite. I added SQLite for Unversal Windows Platforms and SQLite.Net-PCl. It is my simple code
var conn = new SQLiteConnection(
new SQLitePlatformWinRT(),
Path.Combine(ApplicationData.Current.LocalFolder.Path, "Storage.sqlite"));
It is working for desktop. But it is not work for mobile(in device and emulator). I get this exception System.DllNotFoundException:
HResult=-2146233052
Message=Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Source=SQLite.Net.Platform.WinRT
TypeName=""
StackTrace:
at SQLite.Net.Platform.WinRT.SQLite3.SetDirectory(UInt32 directoryType, String directoryPath)
at SQLite.Net.Platform.WinRT.SQLiteApiWinRT..ctor()
at SQLite.Net.Platform.WinRT.SQLitePlatformWinRT..ctor()
at AppDbTest.MainPage.DbConnection()
at AppDbTest.MainPage..ctor()
at AppDbTest.AppDbTest_XamlTypeInfo.XamlTypeInfoProvider.Activate_0_MainPage()
at AppDbTest.AppDbTest_XamlTypeInfo.XamlUserType.ActivateInstance()
I try this method. I reinstall SQLite for Unversal Windows Platforms extension and SQLite.Net-PCl. I created clear project. But it does not work for me.
I add a reference to Visual C++ 2015 Runtime for Universal Windows Platform Apps. It is work for me. I used SQLite for Universal Windows Platform.
Make sure that you current add 2 references
Sqlite for Universal Windows Platfrom
Visual C++ Runtime 2015 for Unversal Windows Platfrom
It's still worked!
Solved in chat.
OP solved it using Nuget console :
Install-Package SQLite.WinRT.UAP
and used "add link" ->"Extensions"->SQLite for Windows Runtime
Suggestion
Cool but would suggest you to use Extension SQLite for Universal App Platform as it encases most of device family and SQLite.WinRT.UAP is not needed.
As in current repo I removed references for Winrt and using these extensions its working fine. Just check if the Sqlite vsix package installed is the correct one on your system.

Build Problems with SQLite-WinRT Wrapper

I am having trouble getting my app to build for ARM target after adding the SQLite-WinRT database wrapper. I could reproduce this with a simple test app as follows:
(This is done in Visual Studio 2013.)
Create an empty Windows 8.1 universal app (WinRT)
Download SQLite for Windows Phone 8.1 and SQLite for Windows Runtime (Windows 8.1) using Tools/Extensions and Updates. Add them to the respective projects' references.
Using NuGet, add SQLite-WinRT package to each project.
Build for x86 (local machine or phone emulator) -> no problems.
Build for ARM (phone device) -> build error shown below (independent of debug or release builds).
There was a mismatch between the processor architecture of the project being built "ARM" and the processor architecture, "x86", of the implementation file "C:\Users\jr\Documents\Visual Studio 2015\Projects\sqlite-test\packages\Sqlite-Winrt.3.8.7.1\lib\wpa81\SQLiteWinRT.dll" for "C:\Users\jr\Documents\Visual Studio 2015\Projects\sqlite-test\packages\Sqlite-Winrt.3.8.7.1\lib\wpa81\SQLiteWinRT.winmd". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and implementation file, or choose a winmd file with an implementation file that has a processor architecture which matches the targeted processor architecture of your project.
I posted a small test project here (Windows Phone 8.1 empty project, added SQLite, added SQLite-WinRT via NuGet).
Go to project properties open build tab and set target platform to ARM
Edit
You have added WinRt sqlite. it is buid on x86 and when you want to build it on ARM process Architecture it cannot build you need to remove WinRTSQlite dll than your project will work fine. Here is Code
Hope this helps
One workaround for the problems with the NuGet package is adding the sqlite-winrt sources to your phone or universal app.
install SQLite for Windows Phone 8.1 (and for universal also Windows Runtime (Windows 8.1)) in Tools -> Extensions and Updates if not done already
add references to the respective projects
download the sources for the sqlite-winrt wrapper
copy the SQLiteWinRTPhone81(RT) (and SQLiteWinRT81 if needed) folders to your solution
add the projects to your solution in Visual Studio (right-click on solution -> Add -> Existing Project)
add references to the respective projects
edit the references for the sqlite-winrt project(s) to point to the correct version of SQLite (right-click project -> Properties -> Common Porperties -> References): add a reference to the current SQLite version in your project and remove the old reference
build your solution
I have downloaded your project and on the references i have found that you are using SQLite-WinRT and sqlite for windows phone 8.1, you don't need both.
as soon as you remove SQLite-WinRT your project start compiling.
EDIT:
inside a universal app you have to add only the right references, if is a phone project just add sqlite for windows phone 8.1, instead on the windows 8.1 app add only the SQLite-WinRT

FileNotFoundException in xamarin.forms in sqlite implementation

In my project where i am using sqlite i get this error.
An exception of type System.IO.FileNotFoundException occurred in SQLite.Net.Platform.WindowsPhone8.DLL but was not handled in user code
Here is a screenshot.
P.S. i got value in variable path as C:\Data\Users\DefApps\AppData{F8267584-1051-4816-8195-EE018BA5155E}\local\Student.db3
Thanks
You're missing Sqlite for Windows Phone. iOS and Android have Sqlite "build in", meaning it is available directly on the platform. Windows Phone ships without Sqlite.
To add it, first prepare your development machine by using Tools -> Extensions and Updates in Visual Studio. Search online for "sqlite windows phone". You must install the one for WP8 (not 8.1). When done, your machine is ready to deploy Sqlite with a WP project.
Next, add a reference to Sqlite to your WP app. Right click References in your WP project. Select Add references and in the menu select Windows Phone SDK -> Extensions and select Sqlite for Windows Phone.

Using SQLite-Net Extensions in winRT

I would like to use the SQLite-Net Extensions library in my winRT project.
https://bitbucket.org/twincoders/sqlite-net-extensions
To support sqlite in my Windows 8.1 App I've currently installed SQLite for Windows Runtime (Windows 8.1) as VS Extension and sqlite-net via NuGet.
Extension: http://visualstudiogallery.msdn.microsoft.com/1d04f82f-2fe9-4727-a2f9-a2db127ddc9a
sqlite: https://www.nuget.org/packages/sqlite-net
To get it working I tried to download the source and build it with the sqlite libs we can use for winRT. In order to add a reference to SQLite for Windows Runtime I need to change the target to Windows 8.1 only. Doing that will result in many errors like: "The name 'BindingsFlags' does not exist in the current context" "Instance argument: cannot convert from 'System.Type' to 'System.Reflection.MemberInfo'"
I've also tried to link the SQLite-Net-PCL directly from my project but in the end it's the same situation.
I really need to add relationships to my sqlite database and would be very very thankful for every help I can get!
Attached you can find a screenshot of my VS2013 where I've changed the references of SQLiteNetExtensions to use the required winRT libraries.
Many many thanks in advance for any help you can give me!
Following steps work for me without the need to download the source and possible compilation error:
(I have the following assumptions: I only target Windows 8.1 [As of yours] and I use Visual Studio Premium 2013 Update 3)
In Visual Studio go to Tools-Extensions & updates-online section and look for sqlite. This package will contain
required SQLite Binaries.
Add a Reference to SQLite for Windows Run-time in your project Reference
Add a Reference to Microsoft Visual C++ Run-time package
In Nuget package manager console run "Install-package sqlite-net"
In Nuget package manager console run "Install-Package SQLiteNetExtensions"
Now you will have a project which Targets Windows 8.1 and also has reference to both SQLiteNetExtensions. Above steps was originally recommended in : Using SQLite in a Windows Store App
Below is the screenshot of the SQLiteDemo project references downloaded from the link I mentioned earlier which also has reference to SQLiteNetExtensions :

Is sqlite db file available under any platform?

For example, can I generate a SQLite db file and put it as a resource in the project. When the project first launches, copy the db into isolated storage without worrying this db file may be unavailable in the phone. Furthermore, can I copy this empty db file into another platform, like android or iPhone, and operate this db by in SQLite api of the platform.
From the SQLite web site:
A database in SQLite is a single disk file. Furthermore, the file format is cross-platform. A database that is created on one machine can be copied and used on a different machine with a different architecture. SQLite databases are portable across 32-bit and 64-bit machines and between big-endian and little-endian architectures.
So yes, when you've validated that the SQLite API is available everywhere you want to use it, that should be fine as a storage format.
EDIT: And yes, SQLite does work on Windows Phone 7, using this Codeplex project or this one.
Yes. We are using the same SQLite database in an iOS, Android and WP7 app. I've written a quick start guide here: http://wirebear.com/blog/2010/11/12/using-sqlite-in-your-wp7-app
The above blog post covers copying your database from your resources to isolated storage and correctly configuring SQLite to work on your device.
The SQLite version is compatible with Android - iOS - WindowsPhone as far I have experimented. I have created SQLite DB on a Mac Desktop and copied it into projects along with data into each of these platforms. Everything worked fine no issues.
Ref:
http://www.sqlite.org/download.html
Precompiled Binaries for Windows Phone 8
sqlite-wp80-winrt-3071502.vsix (2.72 MiB)
A complete VSIX package with an extension SDK and all other components
needed to use SQLite for application development with Visual Studio
2012 targeting Windows Phone 8.0. (sha1:
4cab3fd698402bf30448c64e39001103c10ff82b)
The download page itself lists the entire code and binaries for different platforms. Using a PC/Mac for creating a DB is convenient option.
You can use SQLite manager for doing so on a Windows or Linux PC.
SQLite Manager (Preferred by Myself)
http://sqliteman.com/
There are also extensions for Chrome and Firefox, which makes SQLite Available for almost any platform to Manage them.
Firefox Plugin for managing those files.
https://code.google.com/p/sqlite-manager/
codev.it also allows to enable editing SQLite Files.
As far as DB is concerned, Exporting them from the device is as described by #Jon Skeet
SQLite 3.7 is more compatible with Windows Phone. Since SQLite DBs are backward compatible, there isn't any need to worry weather your DB works on older 2.x version or 3.x..
Hope this helps.
#Bhuro As you want a detailed procedure for using SQLite db in a Windows Phone 7 app, Here is a good post Native Database Programming via Sqlite Client for Windows Phone.
I have successfully followed the same process in my WP app. Try that and let me know if you get any doubt.
Good luck !!

Resources