WP8 : File not Found in SQLite - sqlite

I follow This Post to try SQlite implementation in Windows Phone 8 and I am able to do that. Recently I installed Win 8.1 with VS 2013. Now I again tried the same step to run the previously created example is not working now.
I am getting error in below code.
#if USE_WP8_NATIVE_SQLITE
return (Result)Sqlite3.sqlite3_open_v2(filename, out db, flags, "");
#else
return (Result)Sqlite3.sqlite3_open_v2(filename, out db, flags, null);
#endif
I am getting lite this
Not sure what is wrong with this.
Can any one help me in this ?

You most likely don't have the SQLite for Windows Phone SDK installed (not the .NET-callable wrapper, the actual engine). Download it from http://sqlite.org/download.html and then add a reference to it in your project.

Related

Unable to open SQLite database file from local data store of UWP app

I'm using this section of this official MSDN tutorial: Use a SQLite database in a UWP app but I'm getting the following error:
REMARK: There are many online posts related (or similar) to this issue but none seems to have a solution. Most of these posts are a few years old so I thought this issue would have been resolved by now. Moreover, the above mentioned tutorial is using .NET Standard Class library project, as well. And the online posts regarding the issue do not have .NET Standard involved. So, I was wondering if the issue is caused by the use of .NET Standard library. Regardless, a solution will be greatly appreciated.
SQLite Error 14: 'unable to open database file'
Error occurs at line db.Open() of this code:
public static void InitializeDatabase()
{
using (SqliteConnection db =
new SqliteConnection("Filename=sqliteSample.db"))
{
db.Open();
String tableCommand = "CREATE TABLE IF NOT " +
"EXISTS MyTable (Primary_Key INTEGER PRIMARY KEY, " +
"Text_Entry NVARCHAR(2048) NULL)";
SqliteCommand createTable = new SqliteCommand(tableCommand, db);
createTable.ExecuteReader();
}
}
NOTES:
The line just below the above code reads: This code creates the SQLite database and stores it in the application's local data store. That means the app should have access to that local data store.
I'm using latest version 16.3.5 of VS2019 on Windows 10. The target version on the project is selected as Windows 10 1903 and min version as Windows 10 1903
UPDATE
This similar official 3 years old sample works fine. So, the problem seems to be related to newer versions of .NET Core. But I need to use latest version of .NET Core for other features my app is using that are not available in the older versions.
I also tried this similar old tutorial, but it did not on new version of .NET Core work either - giving exact same error.
The old problem reported in 2016 here to Microsoft seems to have resurfaced again with the new version of .NET Core.
This is a misunderstanding, SqliteConnection db = new SqliteConnection("Filename=sqliteSample.db") can not create a Sqlite file, but access the existing Sqlite database file through the path.
So you need to create a valid sqliteSample.db file and place it in the root directory of the UWP project. Select the content in the Properties -> Build operation to ensure it will be loaded into the application directory.
Update
Please create the sqliteSample.db file in LocalFolder first.
await ApplicationData.Current.LocalFolder.CreateFileAsync("sqliteSample.db", CreationCollisionOption.OpenIfExists);
Then use the path to access the database file
string path = Path.Combine(ApplicationData.Current.LocalFolder.Path, "sqliteSample.db");
using (SqliteConnection db =
new SqliteConnection($"Filename={path}"))
{
// ...
}
Best regards.

deploying Qt/QML App with LocalStorage (Sqlite) on OS X

I'm doing an app with QML that uses LocalStorage to store some informations.
It's working fine when I run in debug mode.
My storage.js that access the database is like that.
.import QtQuick.LocalStorage 2.0 as Sql
// First, let's create a short helper function to get the database connection
function getDatabase() {
return Sql.LocalStorage.openDatabaseSync("MyApp", "0.1", "StorageDatabase", 100000);
}
My Qt .pro file contains the Sql module:
QT += sql
And at first moment it runs fine in Release mode either.
But when I try to deploy on OSX, running macdeployqt like that:
macdeployqt MyApp.app -dmg -qmldir=../MyApp/qml/
First I got one error, but I think that's ok because I don't use MySQL: ERROR: no file at
"/opt/local/lib/mysql55/lib/libmysqlclient.18.dylib"
I'm using sqlite via LocalStorage.
Then trying to run in Release mode it doesn't work anymore, the database access doesn't work, not even the in the deployment it works... now when I try to run the app I got the error:
storage.js:5: ReferenceError: Sql is not defined
The line 5 is this one:
return Sql.LocalStorage.openDatabaseSync("MyApp", "0.1", "StorageDatabase", 100000);
And the Sql name is defined in the first line:
.import QtQuick.LocalStorage 2.0 as Sql
Looking for this error in the internet I found some places telling to do exactly what I did, like here: https://qt-project.org/forums/viewthread/28371
Any clue about this?
I'm using Qt5.2, Quick 2.0, Qt Creator 3.01
The problem was related to this Qt bug that is here since Qt5.1
https://qt-project.org/forums/viewthread/29805/
I've used the script and custom macdeployqt linked in the post to make this work.
Script: https://gist.github.com/lasconic/5965542
Custom macdeployqt: https://github.com/MaximAlien/macdeployqt
It seems that Qt is not giving much attention to desktop development, only that explains a bug like that not fixed yet.

MvvmCross SQLite plugin in Windows Phone 8

I'm creating a cross-platform application (Android, iOS, WP8) which using multiple SQLite databases. I installed MvvmCross.HotTuna.Plugin.Sqlite on all platforms, but it is not working on WP8. I'm getting this exception:
"Could not open database file: C:\\Data\\Users\\DefApps\\AppData\\{284E2D10-051E-48D8-B895 E8126CCE3192}\\Local\\database.sqlite (CannotOpen)".
I'm opening the database like this:
dataService.Initialize(Path.Combine(ApplicationData.Current.LocalFolder.Path, filename));
Then I tried to swith to the new Sqlite plugin (MvvmCross - Community SQLite-Net Plugin), and it giving me strange errors on almost every query:
Message: "not an error"
StackTrace: " at Community.SQLite.SQLite3.Prepare2(sqlite3 db, String query)\r\n at Community.SQLite.SQLiteCommand.Prepare()\r\n at Community.SQLite.SQLiteCommand.<ExecuteDeferredQuery>d__0`1.MoveNext()\r\n at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)\r\n at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)\r\n at Community.SQLite.SQLiteCommand.ExecuteQuery[T]()\r\n at Community.SQLite.SQLiteConnection.Query[T](String query, Object[] args)\r\n at
Any suggestions how can I make it work?
EDIT:
I found out that the reason behind "not an error" was my multi-threading. I used Task.Run and await to create background thread (which worked fine on iOS and Android, but it failed on WP8). I removed that from my code (with #if WINDOWS_PHONE directives) so right now it's working synchronously. But the Community SQLite plugin can't map my SQLite Date type to DateTime. It always gives me the same DateTime: {0001.01.01. 0:00:00}.
Btw how can I use native SQLite? Can you show me a sample? I need to add new SQLite lib to my WP8 project, and implement IDataService, ISQLiteConnectionFactory, and register them on:
Setup.InitializeLastChance()
{
Mvx.LazyConstructAndRegisterSingleton<IDataService, MyOwnDataService>();
Mvx.LazyConstructAndRegisterSingleton<ISQLiteConnectionFactory , MyOwnConnectionFactory>();
}

Exception when using SQLite in WinRT app

I'm building a Windows 8 app, and now I want to use SQLite for this app. I installed SQLite for Windows Runtime through the Visual Studio 2013 extension manager, and I added sqlite-net to my project through NuGet.
I'm trying to create a database in my app.xaml.cs OnLaunched, but I get this exception when I run the project:
Unable to load DLL 'sqlite3': The specified module could not be found.
(Exception from HRESULT: 0x8007007E)
This is very strange because there is no error during compiling. Anyway, I think it tries to tell me that I need to reference an additional DLL: sqlite3.dll, but that doesn't work. I have 6 different DLLs on my file system: both debug and release versions of ARM, x64 and x86. I tried adding the x86 release version to my project but that results in this exception:
A reference to 'C:\Users\Leon\Documents\Visual Studio
2013\Projects\Googalytics\packages\SQLite\x86\sqlite3.dll' could not
be added. Please make sure that the file is accessible, and that it is
a valid assembly or COM component.
It's very sad that the documentation for sqlite-net sucks, it's very outdated (examples don't even work anymore), it's very incomplete and there is no mention of manually adding a DLL either. So I have 2 questions:
How do I fix this particular issue?
Where do I find up to date documentation for sqlite-net?
Edit: the code I use to create the DB is:
private void InitializeDatabase()
{
var db = new SQLiteConnection("Googalytics");
db.CreateTable<Account>();
db.CreateTable<WebProperty>();
db.CreateTable<Profile>();
}
I call that method from here:
InitializeDatabase();
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
if (!rootFrame.Navigate(typeof(MainPage), args.Arguments))
{
throw new Exception("Failed to create initial page");
}
}
// Ensure the current window is active
Window.Current.Activate();
edit2: some more info about my setup:
Visual Studio 2013 RC
Windows 8.1 RTM
SQLite for Windows Runtime 3.8.0.2
sqlite-net 1.0.7
Your project has its build mode currently set to Any CPU, what is the default. Because the SqLite assembly is not build as AnyCPU you need to set your build mode to X86 and add the X86 SqLite reference.
When deploying your app you also need to create 3 packages instead of 1 AnyCPU package.
Because your project is AnyCPU you get the error message when trying to add the x86, x86 is not valid for AnyCPU.
UPDATE
I tried to replicate your problem. I installed the SQLite for Windows Runtime for Visual Studio Ultimate 2012, after that I created a Windows Store Project, then added the SqLite reference after that I added sqlite-net and last I added your code for DB creation.
I modified the code a little bit (path & tables). But my code gives no error at all.
I did not need to reference the SqLite assemblies myself. Because by installing the extension into Visual Studio you get the reference in your extension list (still need to select it, just not add the dlls):
But still like I said in my first answer, you need to set your build mode to something else than 'Any CPU'
My example is on my skydrive (when testing set configuration to x86).
UPDATE 2
Db path:
var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite");
var db = new SQLite.SQLiteConnection(dbPath);

App crashes when using MagicalRecord in release build

Our app uses MagicalRecord to store data in Core Data. It have worked fine so far, but now, after adding fields to my tables, the app crashes, but only in release builds.
When I upgrade via cable, it works just fine, but when I use Ad-Hoc (Enterprise) distribtion to upgrade the app, the app crashes.
The problem is I don't get any debug data on the crash because of this. The only thing I get is a "exited abnormally with signal 11: Segmentation fault: 11" error.
Crash report:
(http://pastebin.com/64c4jvgJ)
I assume the issue might be related to needing migration, but I can't find any good documentation on how this is supposed to work. Any pointers in the right direction is welcome.
Update:
More info -
Before updating my datamodel, i had a store called PAM.sqlite, and a non-versioned store called PAM.xcdatamodeld. Now i have a versioned store, called PAM & PAM 2.
I use this code to attempt an automigration, but it does not work:
[MagicalRecord setDefaultModelNamed:#"PAM 2.xcdatamodel"];
[MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:#"PAM.sqlite"];
You need to specify the extenstion of the data model (e.g. MyProjectDB.momd)
so, the code syntax would be:
[MagicalRecord setDefaultModelNamed:#"MyProjectDB.momd"];
Found the answer here
I had the same issue. Try to add new version in xcdatamodeld. Then activate it as current. Open it in finder. Choose show package content. You will see two files for both of your versions. Replace the one for old version with non-versioned file from your old build. Use this
[MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:#"PAM.sqlite"];
So your project will have two versions of db. And will have an ability to migrate automatically.
Default settings of MagicalRecord for iOS (https://github.com/magicalpanda/MagicalRecord) is something like this
#ifdef DEBUG
[self setShouldDeleteStoreOnModelMismatch:YES];
#else
[self setShouldDeleteStoreOnModelMismatch:NO];
#endif
That means,If there is change in database model in DEBUG mode,they will simply delete older version of data model.I believe this has been fixed in latest version of Magical record.
If not, change it to
#ifdef DEBUG
[self setShouldDeleteStoreOnModelMismatch:NO];
#else
[self setShouldDeleteStoreOnModelMismatch:NO];
#endif
and fix migration code

Resources