Database write permissions

I have an app that stores some data in database. When app starts database is created and app is able to write into it.
Problem begins when I power off my board and power it back on. Database gets deleted and new one is made. So I tried to make database outside sandbox and give app access to it in adef file in requires but it is says it’s read only.

requires:
{
    file:
   {
        /mnt/flash/database.db /data/
   }
}

I also tried to put it in bundles with [w] and [rw] permission:

 bundles:
 {
     file:
     {
       	[w] /bins/data/database.db /data/
      //[rw] /bins/data/database.db /data/
     }
 }

but it still says it’s read only.
I also tried chmod 777 database.db.
So my general question is how to preserve my database is sandboxed app after power off?
Thank you

Are you using SQLite?

@lotam Yes, I use SQLite.

Please set permissions for the directory as explained in

@Alegato Thank you for answering. My code works fine on my Ubuntu PC, so I don’t think it’s code problem… My file is in
/mnt/flash/database/database.db and I gave it write smack label. When I type xattr get, I get name=security.SMACK64, value=app.MyApprwx. My .adef file looks like this:

 requires:
 {
     file:
    {
         /mnt/flash/database.db /data/
    }
 }

When I run my app, file in

/mnt/flash/legato/systems/current/appsWriteable/MyApp/data/database.db

gets name=security.SMACK64; value=_. I than give this file write smack label and when I restart my app, it agains says statement:

Read only: attempt to write a readonly database

I’ ve also tried to move database.db to /home/root.
Again, app is working fine when I don’t give it any extern database, when app creates database in runtime. Then it writes everything fine and all is good. But that database gets deleted after power off.
Thank you

Solution was to add write smack label and to chmod 666 on /mnt/flash/database/database.db