locked
Is Jet API ready for Metro Style app?

    Question

  • I'm sure I have set file access permission on Document folder as well as File Extention, but

    JetInit3() always returns -1032 (ACCESS_DENIED).
    (Process Monitor observation also confirmed that Access Denied error when this API trying to initializing files under Document folder.)

    I'm wondering is ESE APIs ready to use, has anyone made that work?

    (I also noticed that FileAccessSample uses RuntimeBroker.exe to perform file operations, should ESE also do so?)

     

    thanks,

     

     


    • Edited by Mr_Jones_ Sunday, September 25, 2011 11:47 PM
    Sunday, September 25, 2011 6:07 AM

Answers

  • Any "regular" file access is currently brokered through runtimebroker.exe. Since Metro style apps run in Low IL, the only location they can access without using the broker is AppData . That's where you should initialize your Jet Database to. The app can retrieve that folder using the following namespace.

    Windows.Storage.ApplicationData.Current.LocalFolder

     

    using e.g. the C# ESENT interop dll you'd do something like this

    Api.JetCreateInstance(out instance, "instance");
    Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.CircularLog, 1, null);


    // NOTE YOU NEED THE TRAILING SLASH or you'll get access denied
    string jetDir = Windows.Storage.ApplicationData.Current.LocalFolder.Path + "\\";

    // Set paths to AppData
    Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.LogFilePath, 0, jetDir);
    Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.SystemPath, 0, jetDir);
    Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.TempPath, 0, jetDir);

    JET_RSTINFO recinfo;

    // CHANGED 
    VistaApi.JetInit3(ref instance, null, InitGrbit.None);

    I posted a blog post on this here


    Tuesday, October 11, 2011 3:10 AM

All replies

  • Even though you have asked for access to the Documents folder, you cannot use just any API to access the contents of that folder.  You need to use specific Windows Runtime API.

    Since, you need finer grained access (e.g. database), it is better to use the application's local data folder to store your files.  In there your app has full access to all files since this folder is specific only to your app.  The path of the app-local data folder can be retrieved using WinRT API (I think under the namespace Windows.Storage)

    Thanks

    Raman Sharma

    Program Manager, Visual C++

    Monday, September 26, 2011 1:26 AM
  • Raman, I actually begin with the FileAccess sample, one I took from sample gallery, so I am sure file access to ".\" and Document folder were ok.

    I started call JetInit3() with local folder ".\" (which is default folder JET API uees), and then Document folder. Both return the same ACCESS_DENIED error.

    Please note, JetCreateInstance2(), JetInit3() I called is are listed in supported Metro Win32 API (http://msdn.microsoft.com/en-us/library/windows/apps/br205753(v=VS.85).aspx). Original JET API doesn't end with a number.

    One thing I noticed is that some Jet APIs listed missing hyper link for documentation, didn't found any sample from Metro sample gallery either, that's why I asking if ESE is actually being used and ready for Metro app.

    Thanks,


    • Edited by Mr_Jones_ Tuesday, September 27, 2011 12:29 AM
    Tuesday, September 27, 2011 12:19 AM
  • Any "regular" file access is currently brokered through runtimebroker.exe. Since Metro style apps run in Low IL, the only location they can access without using the broker is AppData . That's where you should initialize your Jet Database to. The app can retrieve that folder using the following namespace.

    Windows.Storage.ApplicationData.Current.LocalFolder

     

    using e.g. the C# ESENT interop dll you'd do something like this

    Api.JetCreateInstance(out instance, "instance");
    Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.CircularLog, 1, null);


    // NOTE YOU NEED THE TRAILING SLASH or you'll get access denied
    string jetDir = Windows.Storage.ApplicationData.Current.LocalFolder.Path + "\\";

    // Set paths to AppData
    Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.LogFilePath, 0, jetDir);
    Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.SystemPath, 0, jetDir);
    Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.TempPath, 0, jetDir);

    JET_RSTINFO recinfo;

    // CHANGED 
    VistaApi.JetInit3(ref instance, null, InitGrbit.None);

    I posted a blog post on this here


    Tuesday, October 11, 2011 3:10 AM
  • ESENT will default to Windows.Storage.ApplicationData.Current.LocalFolder. If you specify "mycoolstuff\\database.edb" we'll prepend the ApplicationData path.

    You'll still have to do Gerald's workaround for Beta, though.

    -martin


    Legal Stuff: This posting is provided "AS IS" with no warranties, and confers no rights.

    Tuesday, April 03, 2012 10:14 PM