Solved Sqlite DB is making an in-memory DB instead of a full file DB even though .setDatabaseName is using a Path
-
@SocketSackett said in Sqlite DB is making an in-memory DB instead of a full file DB even though .setDatabaseName is using a Path:
if (!pre_exists || (pre_exists && !m_db.isValid()))
{
m_db = QSqlDatabase::addDatabase("QSQLITE"); // where it holds connection
m_db.setDatabaseName(m_pathDb);
}Did you make sure you enter this if block?
-
@SocketSackett said in Sqlite DB is making an in-memory DB instead of a full file DB even though .setDatabaseName is using a Path:
The once every 10 mins is a bit controlling!
Spam / Bot protection (for new users only, once your amount of posts and your rep increases, it's gone, I guess).
Also, it's not recommended to have the DB connection laying around as member of some class. If you need to get your connection, better use
QSqlDatabase::database()
. -
@jsulm : Yes: My code is exactly like that.
-
@SocketSackett
@jsulm is asking for proof that area of code gets executed. Add this line into theif
:qDebug() << pre_exists << m_pathDb;
and show the result, please.
-
@Pl45m4 : It is a RW-DB so I haven't set the QSQLITE_OPEN_READONLY at all. I'm using the file path for the DB name.
-
@Pl45m4: Thank you for the suggestion. I've applied your suggestion, but I still have the error. But I'm keeping the suggestion in my code because it makes sense. Thx.
-
@JonB : As I said you see it do it the debugger.
-
@SocketSackett DB Path : "D://Bennubio//dataman//data_manager.db" , Pre-exists: true
-
I'm not sure what all fixed this but the approach of if (!pre_exists || (pre_exists && !m_db.isValid())) is a good check to avoid duplicate connection. Before that in a close error I was getting a message that it wasn't closing on the duplicate connection. On Stack Overflow, I found the suggestion to do:
-
@SocketSackett Continuing ... I found the suggestion on Stack Overflow to use: db = QSqlDatabase(); db.removeDatabase(cnxn); after the close was a way to fix the duplicate connection close error. This is wrong. Doing this will not allow the work done to be updated. I removed that, & did a straight DB close, & it is updating once again. Checking for pre-existence of DB path with the QSqlDatabase::database.isValid() will suffice & is a good approach.