0
votes

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))

1
Did you add the SQLite-net files to the same project or did you put them into a separate one? What errors are you getting exactly?Jeroen Vannevel
@JeroenVannevel: thx for your reply. sqlite-net:I tried both ways: within my project and within another project. I have no errors, it's just that SQLite namespace cannot be found, no need to go further. sqlite: when using imports statement, is it 'SQLiteWinRT' ?jhfelectric
Did you add the SQLite extension SDK and the Visual C++ 2013 library to your references?Jeroen Vannevel
@JeroenVannevel: yes, in the project's references, I have 'Microsoft Visual C++ 2013 Runtime Package for Windows' (ExtensionSDKs/Microsoft.VCLibs/12.0) and 'SQLite for Windows Runtime (Windows 8.1)' (ExtensionSDKs/SQLite.WinRT81/3.8.5). I have also specified the target to x86, just to make sure there is no confusion with the various versions.jhfelectric
@jhfelectric - what Jeroen is saying is you need a callable wrapper. The SQLite package you added is part 1 - that is the engine -- now from .NET you need a way to interact with that. SQLite-Net (available via NuGet) is a great way and LINQ-friendly.Tim Heuer

1 Answers

0
votes

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; }
}