Reputation: 4149
What is the cause of following error: QSqlDatabasePrivate::database: unable to open database: unable to open database file Error opening database?
Code is 100% correct, this message appeared when I have reinstalled Windows, Python and PyQt.
EDIT: I have "read-only" flag in folder with .db file properties. It stays gray (half-checked) when I unset it and open folder properties again. I have unset "use simple sharing" flag in folder properties, I have administrator rights, there is no viruses on my computer as I can see. This nasty problem doesn't have a solution on Super User too. How to set proper permissions for sqlite for this folder and file?
Upvotes: 0
Views: 2598
Reputation: 41
Another reason for this problem might be the encoding of the path. Using unicode(name)
solved it in my case.
Upvotes: 1
Reputation: 46479
The above error happens when:
You can see from the following code in src/sql/kernel/qsqldatabase.cpp (as of 4.6.2):
QSqlDatabase QSqlDatabasePrivate::database(const QString& name, bool open)
{
const QConnectionDict *dict = dbDict();
Q_ASSERT(dict);
dict->lock.lockForRead();
QSqlDatabase db = dict->value(name);
dict->lock.unlock();
if (db.isValid() && !db.isOpen() && open) {
if (!db.open())
qWarning() << "QSqlDatabasePrivate::database: unable to open database:" << db.lastError().text();
}
return db;
}
It looks like it's just failing to open the file. It could happen because of permissions, file location change, etc.
Upvotes: 1