DavidHoffman-6474 avatar image
0 Votes"
DavidHoffman-6474 asked Viorel-1 commented

SQL database

I am so frustrated with this that I will start pulling out my hair if I don't find a way to make this work. First off I am no dummy when it comes to SQL databases. I have managed several over the past years, one where I used the SQLite library code in a C++ WPF app and one using MS SQL in a C# app. They worked great and I could find lots of help when I needed it for both, BUT I am getting angry that all my effort leads to dead ends or code failure when I try to use MS SQL, SQL CE, or SQLite3. I am writing my app in UWP C++/WinRT. The app must be written in C++. I find that SQLite only seems to work in UWP C# and C#/CX. I could get the .h files and the code to pass Intellisense, but compile would fail. Something about a missing reference. SQL CE did not work either. I seem to have all the pieces, but it would not compile at all. As far as MS SQL goes, it seems to only work with C# or .NET and not C++. So right now I am dead in the water because I need a database in my app and I cannot find the right information on how to make any one of the 3 work in UWP C++/WinRT. Any help would be appreciated. Also, I really don't care which one I use as long as it works and does not make me walk through a mine field to get it to work. I can also answer any question you have. Thanks.

· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Why do you use UWP ? (microsoft-confirms-uwp-is-not-the-future-of-windows-apps)
UWP is a sandbox with tons of limitations
While all databases work fine in C++ in desktop applications

1 Vote 1 ·

I don't want to get into all the reasons why UWP was chosen. The biggie was I need to share .h files with another app which means no C# and .NET. (Must be C++)

So far I have got everything to work with only one or 2 more hurdles to go.

I also got SQLite3 to work, sort of. After adding the .lib, .dll, and .h files to the project, I got my code to compile and run. Now I just get an error when I try to open the database with this code.

 sqlite3** m_dB = nullptr;
 const char* m_szFile = "data.db?mode=ro";

 void UI_Database::InitializeDatabase(void)
     int sqlError = SQLITE_OK;
     LPCWSTR zPath = ApplicationData::Current().TemporaryFolder().Path().data();
     char zPathBuf[MAX_PATH + 1];
     memset(zPathBuf, 0, sizeof(zPathBuf));
     WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf), NULL, NULL);
     sqlite3_temp_directory = sqlite3_mprintf("%s", zPathBuf);
     sqlError = sqlite3_open(m_szFile, m_dB);
     if (sqlError == SQLITE_OK)

sqlError is 15 which translates into SQLITE_PROTOCOL. I have not figured out why this error happens , but I am on my way with using SQLite3 database.

0 Votes 0 ·

If URI interpetation is disabled, maybe you should write:

 sqlite3* m_dB = nullptr;
 const char* m_szFile = "data.db";
 . . .
 sqlError = sqlite3_open(m_szFile, &m_dB);

0 Votes 0 ·

Which SQLite package that you use to connect your database? Have you referred this document ?

0 Votes 0 ·

Of course I have. I believe it applies to the C# version of UWP. It was no help.

0 Votes 0 ·

1 Answer

Castorix31 avatar image
2 Votes"
Castorix31 answered

I did a test with SQLite and it seems to work, with "VSIX package for Universal Windows Platform development using Visual Studio 2015"

    // Add reference to "SQLite for Universal Windows Platform"       
    // #include "sqlite3.h"
    // Database in AppX directory
    sqlite3* db = NULL;
    char sDatabaseFile[MAX_PATH] = "SQLite_Test.db";
    int rc = sqlite3_open_v2(sDatabaseFile, &db, SQLITE_OPEN_READWRITE, NULL);
    // rc = SQLITE_OK
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.