Skip to content
/ TwoType Public

Xamarin forms example using two different form types

Notifications You must be signed in to change notification settings

b12kab/TwoType

Repository files navigation

July 2021 Update Message

I've updated this example showing the error. Only the SQLite-net was updated from 1.5.231 to the current version at the time of publishing, which is 1.7.335.

The original source version is listed under the v1.0 release. The updated 1.7.335 version is on the master branch.

The SQLiteConnection has changed slightly, where as there isn't any fourth parameter; I've modified the connection to remove the third and fourth parameter.

The error message from the 2021 log file here 2021-07-17 16:13:51.015466-0400 TwoTypeExample.iOS[3734:122935] [logging] API call with invalid database connection pointer

Given no action in two years; if multithreaded database is needed, use another database.

Original Message

This is a repurposing of my existing SQLite Sample adding complexity, now with two different types: a contact and a message (for the contact).

The reason I created this was that I noticed an error showing with the iOS version of SQLite-net-pcl showing "API call with invalid database connection pointer". The specific version used is 1.5.231 (the production version at the time of writing).

When this is compared with the SQLite Sample, it's differing in the implementation of how the SQLiteConnection is used. In SQLite Sample the underlying DatabaseHelper creates and keeps a single static SQLiteConnection. In this project, that isn't done for the simple reason that isn't unit testable. Under the SQLite Sample, it's not possible to unit test under a Mac (or Windows) - with the way it's done here, the connection is created and passed into the Repository. That way the solution can be tested and found working (or not).

Both iOS and Android DependencyService open the SQLite in this way:

SQLiteConnection conn = new SQLiteConnection(_filespec, SQLiteOpenFlags.SharedCache | SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create | SQLiteOpenFlags.FullMutex, true, null);

It works without issue on Android and gives the "[logging] API call with invalid database connection pointer" on iOS. I've tried with and without the SQLiteOpenFlags.SharedCache option, but I thought I'd leave it in for now. While I'm not using this in a multi-threading way, the error falls under that multi-threading category.

The log file and video showing the error are located here.

Based on the log, the error comes up in the Finalize of the SQLiteConnection. In my expermientation, this shows up (and is shown in the video) after waiting a few minutes between going into and out of the contact list / add new contact. I put debug write information into the destructors in the various classes to determine this. I've left it in this version for you to see yourself.

Information from SQLite about the open flags is here.

A useful Xamarin forms forum entry on multi-threading errors is here.

License

The source for this project is released under the MIT license.

About

Xamarin forms example using two different form types

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages