Windows 8.1 Store App and SQLite

0

I need to create a Windows 8.1 Store App, and I need a portable database ; SQLite seems a good choice.

Unfortunately, I spent the entire day trying to understand which bits and pieces I must put together to make it all work. I found many articles targeting Windows 8, but none targeting 8.1. Besides that, I found a lot of wrappers, helpers, etc. which only add to the confusion.

So far, I have installed SQLite 3.8.5 as a VS extension using this link: http://visualstudiogallery.msdn.microsoft.com/1d04f82f-2fe9-4727-a2f9-a2db127ddc9a

I have also installed the NuGet sqlite-net package, using the VS NuGet Manager. My project compiles ok with the 2 new files.

After these two steps, I am still not able to use SQLite. The SQLite namespace is not visible.

My goal is simple: install the official SQLite package. Optionally, I would love being able to use SQLite-net on top of it. Also, can somebody point me to a good SQLite tutorial (VB/C#).

Thanks in advance.

EDIT: I decided to forget sqlite-net for the moment, and tried a simple read of a test database.

Dim s as new SQLiteWinRT.Database("test.db")
Await s.OpenAsync(SQLiteWinRT.SqliteOpenMode.OpenReadWrite)

produces this strange error: compobj.dll is too old for the ole2.dll initialised (Exception from HRESULT: 0x8004000E (OLE_E_WRONGCOMPOBJ))

sqlite
visual-studio-2013
windows-store-apps
windows-8.1
asked on Stack Overflow Aug 3, 2014 by jhfelectric • edited Aug 4, 2014 by jhfelectric

1 Answer

0

You should be able to query Nuget for the latest SQLite assembly that's compatible with Windows 8.1. Once you find it, install it and then follow this pattern:

SQLiteAsyncConnection connection = new SQLiteAsyncConnection(Constants.DATABASE_FILE_NAME);
await connection.CreateTableAsync<Bizmonger.Client.Infrastructure.DAL.Entities.Service>();

var service = CreateSomeService();
await connection.InsertAsync(service);

Your class will require at least a primary key attribute for one of its properties:

public class Service
{
    [PrimaryKey]
    public string ServiceId { get; set; }

    public string UserId { get; set; }

    [MaxLength(250)]
    public string Description { get; set; }

    [MaxLength(30)]
    public string Name { get; set; }
}
answered on Stack Overflow Aug 5, 2014 by Scott Nimrod

User contributions licensed under CC BY-SA 3.0