I want execute queries on my main and backup database, how do i do it? I currently have two connections running until I go to execute a query, I get the error database not open. I'm open to suggestions outside of this program to maintaining an efficient contemporaneous backup system.

My code:
Qt Code:
  1. {
  2. ui->setupUi(this);
  3. //Setup DB connection
  4. db2 = QSqlDatabase::addDatabase("QSQLITE", "main");
  5. db2.setDatabaseName(Path_to_DB);
  6. QFileInfo checkFile(Path_to_DB);
  7.  
  8. if(checkFile.isWritable())
  9. {
  10. if(db2.open())
  11. {
  12. qDebug() << "Connected to database file";
  13. }
  14. }else{
  15. qDebug() << "Database file not found";
  16. }
  17.  
  18. dbb = QSqlDatabase::addDatabase("QSQLITE", "backup");
  19. dbb.setDatabaseName(Path_to_DBBackup);
  20. QFileInfo checkFile2(Path_to_DBBackup);
  21.  
  22. if(checkFile2.isWritable())
  23. {
  24. if(dbb.open())
  25. {
  26. qDebug() << "Connected to database backup file";
  27. }
  28. }else{
  29. qDebug() << "Database file not found";
  30. }
  31.  
  32. QString email = ui->email->text();
  33. QString q = QString("SELECT * FROM users WHERE email = '%1'").arg(email);
  34. QSqlQuery qry;
  35. if(qry.exec(q))
  36. {
  37. if (qry.next())
  38. {
  39. return false;
  40. }
  41. }
  42. else{qDebug() << "Query unsuccessful!";}
  43. }
To copy to clipboard, switch view to plain text mode 

Everything works when I query just one db...

Thanks in advance.