title: SQLiteException:Could not open the database in read/write mode
body: <p>Try to load data from a local db file (preferably in SD Card).</p>
  
  <p>I first check if sd-card is mounted before performing any operation.</p>
  
  <pre><code>    if (isExternalStorageWritable()) {
          loadFile(SharedPref.getDBPath(this), new DataLoaderCallback() {
              @Override
              public void onDataRetrieved(ImportModel importModel) {
  
              }
          });
      }
  </code></pre>
  
  <p>this basically calls this part of the code that crashses the app.</p>
  
  <pre><code>private SQLiteDatabase connect() {
          String dbPath = SharedPref.getManifestPath(mContext);
          File dbfile = new File(dbPath);
          if (dbfile.exists()) {
  
              return SQLiteDatabase.openDatabase(dbfile.getAbsolutePath(), null, SQLiteDatabase.OPEN_READWRITE);
          }
          return null;
      }
  </code></pre>
  
  <p>and this is the error :</p>
  
  <pre><code>Failed to open database '/storage/sdcard1/Alarms/data/manifest'.
                                                                      android.database.sqlite.SQLiteException: not an error (code 0): Could not open the database in read/write mode.
                                                                          at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
                                                                          at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:212)
                                                                          at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:196)
                                                                          at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
                                                                          at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
                                                                          at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
                                                                          at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:806)
                                                                          at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:791)
                                                                          at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
                                                                          at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
  </code></pre>
  
  <p>When I use:</p>
  
  <pre><code>  return SQLiteDatabase.openDatabase(dbfile.getAbsolutePath(), null, SQLiteDatabase.OPEN_READONLY);
  </code></pre>
  
  <p>It does work but I can only read from the file. I want to read and write. Hence, <code>OPEN_READWRITE</code> .
  The file has read and write permission , and I have this permissions added in manifest.</p>
  
  <pre><code>    &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  </code></pre>
  
  <p>How do I fix this ?</p>