Question

We're having issues with our Sqlite PCL Project.

The issues

1) Anywhere that references Mono.Data.Sqlite.SqliteConnection shows the following error.

Module 'System, Version 4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' should be referenced.

2) Anything trying to use File.Exists is showing a compiler error

Cannot resolve symbol 'File'

The particulars

We're using .NET Portable Subset 158

  • C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile158\

We've included

  • Mono.Data.Sqlite
    • C:\Program Files (x86)\Mono-3.2.3\lib\mono\4.5\Mono.Data.Sqlite.dll
  • System.Data
    • C:\Program Files (x86)\Mono-3.2.3\lib\mono\4.5\System.Data.dll

I have no idea where to go from here.

Here's a class file containing the issues with SqliteConnection

using System;
using Mono.Data.Sqlite;

namespace OurApplication.AppCore.Data.Sqlite
{
    public class DbConnectionProvider : IDbConnectionProvider
    {
        private readonly string _connectionString;

        public DbConnectionProvider(string sqliteDatabasePath, string databaseName)
        {
            // the sqliteDatabasePath is hard coded in 'Data.Sqlite.DbProvider'
            //     _sqliteDatabasePath = "{0}.sqlite3";
            _connectionString = string.Format("Data Source=" + sqliteDatabasePath, databaseName);
        }

        public SqliteConnection GetOpenConnection()
        {
            var connection = new SqliteConnection(_connectionString);
            if (connection == null) throw new Exception("Could not create a database connection.");

            connection.Open();

            return connection;
        }
    }
}

Gist with more code examples

If this approach isn't feasible, I'm open to other alternatives. I'm looking into Sqlite.Net but the API doesn't really do what I want with regards to a custom DbReader and such.

I'm also interested in Stuart Lodge's MvvmCross Sqlite stuff, but really have no idea how to integrate the platform specific goodness. Honestly, I can't even figure out how to Execute Parameterized Queries.

I think my preference would be to use MvvmCross-SQLite if I can just get it figured out.

For references, this is how our Solution is structured.

  • OurApplication.App.Droid
  • OurApplication.AppCore
  • OurApplication.AppCore.Data.Sqlite (This is the project I'm working in.)
  • OurApplication.AppCore.Data.SqlServer
Was it helpful?

Solution

For non-portable APIs MvvmCross generally provides interfaces within PCLs with platform specific implementations on each platform.

The pattern used is called "plugins" - but really these are just a simple layer on top of an IoC container. You can see more about this on:

For File.Exists, MvvmCross provides an IMvxFileStore api - see https://github.com/MvvmCross/MvvmCross/blob/v3/Plugins/Cirrious/File/Cirrious.MvvmCross.Plugins.File/IMvxFileStore.cs

For SQLite MvvmCross has wrapped the SQLite-net library.

  • The original attempt to do this is in https://github.com/MvvmCross/MvvmCross/tree/v3/Plugins/Cirrious/Sqlite and is based off an early 2012 version of SQLite-net. A video intro to this is available in N-10 in http://mvvmcross.wordpress.com. This project has now been marked as obsolete simply because I don't plan to do any updates to it.
  • The newer attempt at portable SQLite-net has been put in its own repo to allow more people to contribute to it without confusing the main MvvmCross repo. It is in https://github.com/MvvmCross/MvvmCross-Sqlite - it is based off the latest SQLite-net (late 2013) which was split into interface and non-interface parts by @jarroda. The same N-10 video intro from http://mvvmcross.wordpress.com should work with this project too - just with a different namespace.

    This source is currently live and builds fine here in my stable WinRT/WP7/Xamarin VS2012 environment. There will be changes in the coming weeks to address changes forced on MvvmCross by the latest Xamarin and Microsoft PCL changes. I'm afraid no-one can help with "spewing out errors" - that's not a techie term anyone can really help with.

There is at least one other PCL adaption of SQLite-net I've seen recently - but I can't find a link to that at present.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top