title: ATTACH DATABASE gives "database is already in use" on Android
body: <p>In a native app project both on iOS and android we encountered issues with <strong>sqlite3</strong> on android. We want to open two databases and <strong>attach</strong> one database to the second database via <a href="https://www.sqlite.org/lang_attach.html" rel="noreferrer">ATTACH DATABASE</a> (sql-command).</p>
  
  <h2>What we do:</h2>
  
  <ol>
  <li><p>open sqlite3 database "user.db" (final native filepath on android
  device is '/data/user/0/com.company.app/databases/user.db', we use <strong>android.database.sqlite.SQLiteDatabase</strong>)</p></li>
  <li><p>open sqlite3 database "system.db"</p></li>
  <li><p>attach the user-database to the system database:</p></li>
  </ol>
  
  <p>on the SQLiteDatabase-Instance for system.db-database, we execute</p>
  
  <pre><code>ATTACH DATABASE '/data/user/0/com.company.app/databases/user.db' AS dbUser
  </code></pre>
  
  <h2>Result:</h2>
  
  <p>This gives the following error:</p>
  
  <blockquote>
    <p>Database dbUser is already in use (code 1)</p>
  </blockquote>
  
  <p>The same sql-statement on sqlite3 for iOS is working fine without any errors.</p>
  
  <p>For the sake of completeness. The databases are opened with the following statement:</p>
  
  <pre><code>import android.database.sqlite.SQLiteDatabase;
  
  SQLiteDatabase mydb = SQLiteDatabase.openDatabase(dbfile.getAbsolutePath(), null, openFlags);
  </code></pre>
  
  <p>Asking google for this kind of error message gives lots of sites stating, that it is not allowed to use TEMP as database alias. Since we use "dbUser" and not TEMP, there should be another reason. We can't figure out right now. </p>
  
  <p>Can someone help?</p>