title: App force close clearing up SQLite entries
body: <p>I have created SQLite db using following approach. When user first login I insert few records to this DB. On subsequent logins I use this information for further processing. This is working fine as long as user don't force close app using <a href="http://support.apple.com/en-us/HT5137" rel="nofollow">approach described here</a>. </p>
  
  <p>If user force close and login to app again, all the information he/she entered was lost. Now my question is, how can I make sure "force close" won't wipe out my data? Any help appreciated. </p>
  
  <p><strong>onViewLoad, create table if required:</strong></p>
  
  <pre><code>//Database code start.
      NSArray *dirPaths;
      NSString *docsDir;
      dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      docsDir = dirPaths[0];
      _databasePath = [[NSString alloc] initWithString:[docsDir stringByAppendingString:@"users.db"]];
  
      sqlite3* db = NULL;
      int rc=0;
  
      rc = sqlite3_open_v2([_databasePath cStringUsingEncoding:NSUTF8StringEncoding], &amp;db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
      if (SQLITE_OK != rc)
      {
          sqlite3_close(db);
          NSLog(@"Failed to open db connection");
      }
      else
      {
          char * query ="CREATE TABLE IF NOT EXISTS USERS(username TEXT, userid INTEGER NOT NULL)";
          char * errMsg;
          rc = sqlite3_exec(db, query,NULL,NULL,&amp;errMsg);
  
          if(SQLITE_OK != rc)
          {
              NSLog(@"Failed to create table rc:%d, msg=%s",rc,errMsg);
          }
  
          sqlite3_close(db);
      }
      //END of table creation.
  </code></pre>
  
  <p>on "Login button click"</p>
  
  <pre><code>//Start SQLite DB operation.
                          sqlite3* db = NULL;
                          int rc=0;
                          rc = sqlite3_open_v2([_databasePath cStringUsingEncoding:NSUTF8StringEncoding], &amp;db, SQLITE_OPEN_READWRITE , NULL);
                          if (SQLITE_OK != rc)
                          {
                              sqlite3_close(db);
                              NSLog(@"Failed to open db connection");
                          }
                          else
                          {
                              NSString *insertSQL = [NSString stringWithFormat:
                                                     @"INSERT INTO USERS(username, userid) values (\"%@\",\"%@\")",
                                                     uName,uID];
                              char * errMsg;
                              rc = sqlite3_exec(db, [insertSQL UTF8String] ,NULL,NULL,&amp;errMsg);
                              if(SQLITE_OK != rc)
                              {
                                  NSLog(@"Failed to insert record  rc:%d, msg=%s",rc,errMsg);
                              }
                              sqlite3_close(db);
                          }
  
                          //End of sqlite DB operation.
  </code></pre>
  
  <p>As long as user don't forceclose app, data didn't wipe out.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>After spending lot of hours I see that folder paths are correct, but I am getting "unable to open database file" issue on phone.</p>