ios - file is encrypted or is not a database message when application Become Active -
i have random case of not able access sqlite database ipad app. have used fmdatabase access sqlite database , have not enable dataprotection in provisioning profile.also sqlite version 3. happens passcode enabled devices. when device goes sleep while app in foreground error comes randomly when user enter passcode. once user enter passcode app comes foreground , database inaccessible sqlite code 26: file encrypted or not database
can 1 me solve issue.
i have added 1 place occurred
-(nsstring*)getvalueforsetting:(nsstring*)settingname{ __block nsstring *settingvalue ; nsstring *sql = [nsstring stringwithformat:@"select settingvalue settings settingname = '%@' ",settingname]; fmdatabasequeue *queue = [fmdatabasequeue databasequeuewithpath:[databaseutility getdbpath]]; @try{ [queue indatabase:^(fmdatabase *database) { fmresultset *results = [database executequery:sql]; if (![database haderror]) { if([results next]){ settingvalue = [results stringforcolumn:@"settingvalue"]; } } else { nslog(@"database error,get setting value %d: %@", [database lasterrorcode], [database lasterrormessage]); } [results close]; }]; } @catch(nsexception *exception){ nslog(@"0002,err,memberdataaccess,getipaddisplayname:(nsstring*)memberid, %@",[exception description]); } @finally { [queue close]; } return settingvalue; }
here got following out put
database error,get setting value 26: file encrypted or not database
edit 1:
i able isolated issue occurring code snippet. in applicationdidbecomeactive:
method i'm calling following method. method used redirect nslogs file.
-(void) redirectconsolelogtodocumentfolder { nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; nsstring *custompath=[documentsdirectory stringbyappendingpathcomponent:@"logfiles"]; nsfilemanager *manager=[nsfilemanager defaultmanager]; if (![manager fileexistsatpath:custompath]) [manager createdirectoryatpath: custompath withintermediatedirectories:yes attributes:nil error:nil]; nslog(@" devicelogs class : custom path: %@",custompath); nsdateformatter *dateformat = [[nsdateformatter alloc] init]; [dateformat setdateformat:@"yyyy-mm-dd"]; [globalsettingssingelton setlocale:&dateformat]; nsdate *today = [nsdate date]; nsstring *todaysdate = [[nsstring alloc]initwithformat:@"%@",[dateformat stringfromdate:today]]; nsstring *logfile = [[nsstring alloc]initwithformat:@"log_%@.txt",todaysdate]; nsstring *logpath = [custompath stringbyappendingpathcomponent:logfile]; freopen([logpath cstringusingencoding:nsasciistringencoding],"a+",stderr); }
some times after calling method db file corrupted or encrypted , gives above mentioned error when try access db. if comment line app works without issue.
to isolate issue called 2 db access methods before freopen() , after. db access method added after method gives file encrypted or not database
error while previous db access method runs without issue.
i cant imagine issue since nslog redirection nothing db file. how comes encrypted or corrupted. please 1 explain this.
hi able find reason finally. first this article helped me clue sqlite application corruption. indicate 1 reason have suspect related problem.
we have seen cases file descriptor open on log file, file descriptor closed , reopened on sqlite database. later, other thread continued write log information old file descriptor, not realizing log file had been closed already. because file descriptor had been reopened sqlite, information intended go log file ended overwriting parts of sqlite database, leading corruption of database.
by writing sample application able recreate issue. used 2 threads. 1 thread continuously call redirectconsolelogtodocumentfolder
method using timer. other thread used run sql queries in loop , add nslog entries withing that. after time got file encrypted or not database
error message.
as fix removed redirectconsolelogtodocumentfolder
method call in applicationdidbecomeactive:
method , keep in didfinishlaunchingwithoptions:
method guarantee fix due following reasons.
- log file closed when app beginning run.
- there 1 thread alive (which main main thread).
- log file opening sequential process.
Comments
Post a Comment