title: Cannot perform this operation because there is no current transaction appears when copying multiple files in Android
body: <p>I'm a beginner in SQLite and Android. I need to copy tables of one db (Ex: DB1) to another db (Ex: DB2). According to my code, one database and relevant tables are created in on create. When the button press , I need to create the other table and copy data from one table to another. Both two tables are creating, but data are not copying. I'm getting no current transaction appears in logcat. There are similar questions here ,but I didn't get any solution to my problem regarding this. Please help me to fix this.</p>
  
  <pre><code>public class DatabaseHandler extends SQLiteOpenHelper {
  
  private static final int DATABASE_VERSION = 1;
  
  // Database Name
  public static final String DATABASE_NAME = "TempSignageDBManager";
  
  // table names
  private static final String TABLE_SCHEDULE = "Schedule";
  private static final String TABLE_IMAGETIME = "ImageTime";
  private static final String TABLE_REBOOT = "Reboot";
  private static final String TABLE_RSS = "RSS";
  private static final String TABLE_HEADER = "Header";
  private static final String TABLE_SCROLL = "Scroll";
  private static final String TABLE_WEBSITE = "Website";
  private static final String TABLE_VIDEOS = "Videos";
  private static final String TABLE_IMAGES = "Images";
  private static final String TABLE_HEADERS = "Headers";
  private static final String TABLE_SCROLLS = "Scrolls";
  private static final String TABLE_WEBSITES = "Websites";
  
  // Common column names
  private static final String KEY_ID = "id";
  private static final String KEY_CREATED_AT = "created_at";
  
  // Schedule Table - Columns names
  private static final String KEY_START_TIME = "StartTime";
  private static final String KEY_END_TIME = "EndTime";
  private static final String KEY_START_DATE = "StartDate";
  private static final String KEY_END_DATE = "EndDate";
  private static final String KEY_TEMPLATE = "Template";
  private static final String KEY_PLAYLIST = "PlayList";
  
  // ImageTime Table - Columns names
  private static final String KEY_FILE_PATH = "FilePath";
  private static final String KEY_IMAGE_TIME = "ImageTime";
  
  // Reboot  Table - Columns names
  private static final String KEY_REBOOT_TIME = "RebootTime";
  
  // RSS  Table - Columns names
  private static final String KEY_RSS_TIME = "RssTime";
  
  // Header Table - Columns names
  private static final String KEY_HEADER_NAME = "thname";
  private static final String KEY_HEADER_FONT = "thfont";
  private static final String KEY_HEADER_SIZE = "thsize";
  private static final String KEY_HEADER_STYLE = "thstyle";
  private static final String KEY_HEADER_COLOR = "thcolor";
  
  // Scroll Table - Columns names
  private static final String KEY_SCROLL_NAME = "txname";
  private static final String KEY_SCROLL_FONT = "txfont";
  private static final String KEY_SCROLL_SIZE = "txsize";
  private static final String KEY_SCROLL_STYLE = "txstyle";
  private static final String KEY_SCROLL_COLOR = "txcolor";
  private static final String KEY_SCROLL_SPEED = "txspeed";
  
  // Website  Table - Columns names
  private static final String KEY_WEBSITE_NAME = "wname";
  
  // Videos Table - Columns names
  private static final String KEY_VIDEO_PLAYLIST = "PlayList";
  private static final String KEY_VIDEO_TEMPLATE = "Template";
  private static final String KEY_VIDEO_NAME = "VideoName";
  
  // Images Table - Columns names
  private static final String KEY_IMAGE_PLAYLIST = "PlayList";
  private static final String KEY_IMAGE_TEMPLATE = "Template";
  private static final String KEY_IMAGE_NAME = "ImageName";
  private static final String KEY_IMAGE_ZONE = "ImageZone";
  
  // Headers Table - Columns names
  private static final String KEY_HEADER_PLAYLIST = "PlayList";
  private static final String KEY_HEADER_TEMPLATE = "Template";
  private static final String KEY_HEADER = "Header";
  
  // Scrolls Table - Columns names
  private static final String KEY_SCROLLER_PLAYLIST = "PlayList";
  private static final String KEY_SCROLLER_TEMPLATE = "Template";
  private static final String KEY_SCROLLER = "Scroll";
  
  // Websites Table - Columns names
  private static final String KEY_WEBSITE_PLAYLIST = "PlayList";
  private static final String KEY_WEBSITE_TEMPLATE = "Template";
  private static final String KEY_WEBSITE = "Website";
  
  public Context cont;
  
  public DatabaseHandler(Context context) {
      super(context, DATABASE_NAME, null, DATABASE_VERSION);
      this.cont = context;
  
  }
  
  // Schedule table create statement
  String CREATE_TABLE_SCHEDULE = "CREATE TABLE " + TABLE_SCHEDULE + "("
          + KEY_START_TIME + " VARCHAR," + KEY_END_TIME + " VARCHAR," + KEY_START_DATE + " VARCHAR,"
          + KEY_END_DATE + " VARCHAR," + KEY_TEMPLATE + " VARCHAR," + KEY_PLAYLIST + " VARCHAR"  + ")";
  
  
  // ImageTime table create statement
  String CREATE_TABLE_IMAGETIME = "CREATE TABLE " + TABLE_IMAGETIME + "("
          + KEY_FILE_PATH + " VARCHAR," + KEY_IMAGE_TIME + " VARCHAR" + ")";
  
  
  // Reboot table create statement
  String CREATE_TABLE_REBOOT = "CREATE TABLE " + TABLE_REBOOT + "("
          + KEY_REBOOT_TIME + " VARCHAR" + ")";
  
  
  // RSS table create statement
  String CREATE_TABLE_RSS = "CREATE TABLE " + TABLE_RSS + "("
          + KEY_RSS_TIME + " VARCHAR" + ")";
  
  
  // Header table create statement
  String CREATE_TABLE_HEADER = "CREATE TABLE " + TABLE_HEADER + "("
          + KEY_HEADER_NAME + " VARCHAR," + KEY_HEADER_FONT + " VARCHAR," + KEY_HEADER_SIZE + " VARCHAR,"
          + KEY_HEADER_STYLE + " VARCHAR," + KEY_HEADER_COLOR + " VARCHAR" + ")";
  
  
  // Scroll table create statement
  String CREATE_TABLE_SCROLL = "CREATE TABLE " + TABLE_SCROLL + "("
          + KEY_SCROLL_NAME + " VARCHAR," + KEY_SCROLL_FONT + " VARCHAR," + KEY_SCROLL_SIZE + " VARCHAR,"
          + KEY_SCROLL_STYLE + " VARCHAR," + KEY_SCROLL_COLOR + " VARCHAR," + KEY_SCROLL_SPEED + " VARCHAR"  + ")";
  
  
  // Website table create statement
  String CREATE_TABLE_WEBSITE = "CREATE TABLE " + TABLE_WEBSITE + "("
          + KEY_WEBSITE_NAME + " VARCHAR" + ")";
  
  
  // Videos table create statement
  String CREATE_TABLE_VIDEOS = "CREATE TABLE " + TABLE_VIDEOS + "("
          + KEY_VIDEO_PLAYLIST + " VARCHAR," + KEY_VIDEO_TEMPLATE + " VARCHAR," + KEY_VIDEO_NAME + " VARCHAR"
          + ")";
  
  
  // Images table create statement
  String CREATE_TABLE_IMAGES = "CREATE TABLE " + TABLE_IMAGES + "("
          + KEY_IMAGE_PLAYLIST + " VARCHAR," + KEY_IMAGE_TEMPLATE + " VARCHAR," + KEY_IMAGE_NAME + " VARCHAR,"
          + KEY_IMAGE_ZONE + " VARCHAR" + ")";
  
  
  // Headers table create statement
  String CREATE_TABLE_HEADERS = "CREATE TABLE " + TABLE_HEADERS + "("
          + KEY_HEADER_PLAYLIST + " VARCHAR," + KEY_HEADER_TEMPLATE + " VARCHAR," + KEY_HEADER + " VARCHAR"
          + ")";
  
  
  @Override
  public void onCreate(SQLiteDatabase db) {
  
      db.setTransactionSuccessful();
      db.endTransaction();  
  
      db.execSQL("attach database ? as aa", new String[]{"/data/data/com.example.databasecopy/databases/Signage"});
      db.beginTransaction();  
  
      db.execSQL(CREATE_TABLE_SCHEDULE);
      db.execSQL(CREATE_TABLE_IMAGETIME);
      db.execSQL(CREATE_TABLE_REBOOT);
      db.execSQL(CREATE_TABLE_RSS);
      db.execSQL(CREATE_TABLE_HEADER);
      db.execSQL(CREATE_TABLE_SCROLL);
      db.execSQL(CREATE_TABLE_WEBSITE);
      db.execSQL(CREATE_TABLE_VIDEOS);
      db.execSQL(CREATE_TABLE_IMAGES);
      db.execSQL(CREATE_TABLE_HEADERS);
  
      db.execSQL("attach database ? as a", new String[]{"/data/data/com.example.databasecopy/databases/TempSignageDBManager"});
  
  
      String sql =
  
              "INSERT INTO (a.Schedule) SELECT * FROM (aa.tempSchedule)";
  
      db.execSQL(sql);
      db.endTransaction();    
      db.execSQL("DETACH a"); 
      db.execSQL("DETACH aa");
  
      db.endTransaction();
  }   }
  </code></pre>
  
  <p>Logcat</p>
  
  <pre><code>    01-17 14:45:09.510: E/AndroidRuntime(5508): FATAL EXCEPTION: main
  01-17 14:45:09.510: E/AndroidRuntime(5508): Process: com.example.databasecopy, PID: 5508
  01-17 14:45:09.510: E/AndroidRuntime(5508): java.lang.IllegalStateException: Cannot perform this operation because there is no current transaction.
  01-17 14:45:09.510: E/AndroidRuntime(5508):     at android.database.sqlite.SQLiteSession.throwIfNoTransaction(SQLiteSession.java:915)
  01-17 14:45:09.510: E/AndroidRuntime(5508):     at android.database.sqlite.SQLiteSession.endTransaction(SQLiteSession.java:398)
  01-17 14:45:09.510: E/AndroidRuntime(5508):     at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:538)
  01-17 14:45:09.510: E/AndroidRuntime(5508):     at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:263)
  01-17 14:45:09.510: E/AndroidRuntime(5508):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
  01-17 14:45:09.510: E/AndroidRuntime(5508):     at com.example.databasecopy.MainActivity$1.onClick(MainActivity.java:70)
  01-17 14:45:09.510: E/AndroidRuntime(5508):     at android.view.View.performClick(View.java:4449)
  01-17 14:45:09.510: E/AndroidRuntime(5508):     at android.view.View$PerformClick.run(View.java:18483)
  01-17 14:45:09.510: E/AndroidRuntime(5508):     at android.os.Handler.handleCallback(Handler.java:733)
  01-17 14:45:09.510: E/AndroidRuntime(5508):     at android.os.Handler.dispatchMessage(Handler.java:95)
  01-17 14:45:09.510: E/AndroidRuntime(5508):     at android.os.Looper.loop(Looper.java:136)
  01-17 14:45:09.510: E/AndroidRuntime(5508):     at android.app.ActivityThread.main(ActivityThread.java:5398)
  01-17 14:45:09.510: E/AndroidRuntime(5508):     at java.lang.reflect.Method.invokeNative(Native Method)
  01-17 14:45:09.510: E/AndroidRuntime(5508):     at java.lang.reflect.Method.invoke(Method.java:515)
  01-17 14:45:09.510: E/AndroidRuntime(5508):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
  01-17 14:45:09.510: E/AndroidRuntime(5508):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:680)
  01-17 14:45:09.510: E/AndroidRuntime(5508):     at dalvik.system.NativeStart.main(Native Method)
  01-17 14:45:09.581: E/dalvikvm(1834): heapsize Dalvik_dalvik_system_VMRuntime_nativeMinimumHeapSize 4194304
  01-17 14:45:09.581: E/dalvikvm(1834): heapsize dvmMinimumHeapSize 4194304
  01-17 14:45:09.581: E/dalvikvm(1834): heapsize dvmMinimumHeapSize set minimumSize 4194304
  01-17 14:45:10.051: E/dalvikvm(1834): heapsize Dalvik_dalvik_system_VMRuntime_nativeMinimumHeapSize 4194304
  01-17 14:45:10.051: E/dalvikvm(1834): heapsize dvmMinimumHeapSize 4194304
  01-17 14:45:10.051: E/dalvikvm(1834): heapsize dvmMinimumHeapSize set minimumSize 4194304
  </code></pre>
  
  <p>MainActivity Class</p>
  
  <pre><code>public class MainActivity extends Activity  {
   private DatabaseHandler dBHelper;
  
   SQLiteDatabase SQLdb;
   Button button;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      Button btn = (Button) findViewById(R.id.button1);
  
      SQLdb = openOrCreateDatabase("TempSignage",Context.MODE_PRIVATE, null);
      SQLdb.execSQL("CREATE TABLE IF NOT EXISTS tempSchedule(StartTime VARCHAR,EndTime VARCHAR,StartDate VARCHAR,EndDate VARCHAR,Template VARCHAR,PlayList VARCHAR);");   
      SQLdb.execSQL("CREATE TABLE IF NOT EXISTS tempImageTime(FilePath VARCHAR,Time VARCHAR);");
      SQLdb.execSQL("CREATE TABLE IF NOT EXISTS tempReboot(Time VARCHAR);");
  
      SQLdb.execSQL("CREATE TABLE IF NOT EXISTS tempHeader(thname VARCHAR,thfont VARCHAR,thsize VARCHAR,thstyle VARCHAR,thcolor VARCHAR);");
      SQLdb.execSQL("CREATE TABLE IF NOT EXISTS tempScroll(txname VARCHAR,txfont VARCHAR,txsize VARCHAR,txstyle VARCHAR,txcolor VARCHAR,txspeed VARCHAR);");
      SQLdb.execSQL("CREATE TABLE IF NOT EXISTS tempWebsite(wname VARCHAR);");
  
      SQLdb.execSQL("CREATE TABLE IF NOT EXISTS tempVideos(PlayList VARCHAR,Template VARCHAR,VideoName VARCHAR);");
      SQLdb.execSQL("CREATE TABLE IF NOT EXISTS tempImages(PlayList VARCHAR,Template VARCHAR,ImageName VARCHAR,ImageZone VARCHAR);");
      SQLdb.execSQL("CREATE TABLE IF NOT EXISTS tempHeaders(PlayList VARCHAR,Template VARCHAR,Header VARCHAR);");
  
  
      SQLdb.execSQL("insert into tempSchedule values('er','erer','4t','rt','ere','feef')");
      SQLdb.execSQL("insert into tempImageTime values('2sfsf','444')");
      SQLdb.execSQL("insert into tempReboot values('343434')");
  
      SQLdb.execSQL("insert into tempHeader values('sdd','de','ssert','sdsd','ererer')");
      SQLdb.execSQL("insert into tempScroll values('5','fg','45','jyj','tyty','55')");
      SQLdb.execSQL("insert into tempWebsite values('sdsdds')");
  
  
      SQLdb.execSQL("insert into tempVideos values('sdwr','efefe','rtrt')");
      SQLdb.execSQL("insert into tempImages values('yyyy','hiiioo','ukjf','oioior')");
      SQLdb.execSQL("insert into tempHeaders values('6','eete','ftytf')");
  
  
      SQLdb.execSQL("insert into tempWebsite values('6','efefeef','rtrt')");*/
  
      btn.setOnClickListener(new View.OnClickListener() {
  
  
          public void onClick(View v) {
               dBHelper = new DatabaseHandler(getBaseContext());
               dBHelper.getWritableDatabase();
  
  
          }
      });   
   }}
  </code></pre>