locked
SQLite can't write to database

    Question

  • Are there any special file permissions rules with WinRT apps? I haven't been able to find anything, but when I try to write to my SQLite database I get a file permissions error.

    rc = sqlite3_open(zDBPathBuf, &m_db);

    char* sql; sql = "SELECT * from SHAPETYPES"; const char* data = "Callback function called"; rc = sqlite3_exec(m_db, sql, sqlCallback, (void*)data, &zErrMsg);

    static int sqlCallback(void *NotUsed, int argc, char** argv, char** azColName)	
    {		
         int i;		
         for(i=0; i < argc; i++)		
         {			
              wchar_t wColName[100];	
    	  size_t* ColNameLength = new size_t(strlen(azColName[i])+1);		
              mbstowcs_s(ColNameLength, wColName, *ColNameLength,  azColName[i], *ColNameLength);
              OutputDebugString(wColName);		
              wchar_t wColVal[100];		
              size_t* ValNameLength = new size_t(strlen(argv[i] ? argv[i] : "NULL")+1);
              mbstowcs_s(ValNameLength, wColVal, *ValNameLength, argv[i] ? argv[i] : "NULL", *ValNameLength);	
              OutputDebugString(wColVal);	
              OutputDebugString(L"\n");	
         }		
         return 0;	
    }
    The database opens correctly and I can execute the select statement I have above, but if I try to execute an Insert statement I get a permissions error. 

    Friday, November 15, 2013 8:37 PM

Answers

  • You cannot deploy to the application data folder. You will need to copy the database there when the user first runs the app.

    You can reference the app data folder with the ms-appdata URI scheme.

    --Rob

    • Marked as answer by Carbaholic Thursday, November 21, 2013 9:29 PM
    Monday, November 18, 2013 6:57 PM
    Owner

All replies

  • Where is your database? My guess is that it is in your install directory. The SQLite database needs to be in the application data folder.

    Windows Store apps have write access only to their application data folders. They can read from their install directory, but not write to it.

    This isn't a special rule: it applies in general to desktop apps as well.

    What is special to Windows Store apps is that they don't have direct read or write access anywhere else. They can get access by user permission using file brokers and the StorageFile object.

    --Rob


    Saturday, November 16, 2013 1:55 AM
    Owner
  • So, how do I set the build properties of my SQLite database so that it will deploy to the application data folder?

    Also, how would I form a relative path to the application's application data folder?

    Thank!

    Eric

    Monday, November 18, 2013 4:48 PM
  • You cannot deploy to the application data folder. You will need to copy the database there when the user first runs the app.

    You can reference the app data folder with the ms-appdata URI scheme.

    --Rob

    • Marked as answer by Carbaholic Thursday, November 21, 2013 9:29 PM
    Monday, November 18, 2013 6:57 PM
    Owner
  • Thank you! I'll give that a try
    • Edited by Carbaholic Tuesday, November 19, 2013 11:01 PM
    Tuesday, November 19, 2013 11:01 PM