[Qt-interest] QSqlQuery::exec: database not open error
Robert Hairgrove
evorgriahr at hispeed.ch
Thu Feb 3 17:03:12 CET 2011
On Thu, 2011-02-03 at 19:52 +0530, Gigin Jose wrote:
> I am developing a QT application for my ARM based embedded device. In
> my application, I am working on two databases, one is the local
> database on the memory of the device and the other is on a remote MS
> SQL server desktop. Here is how I initialize both the databases:
>
> QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE","local");
> QSqlDatabase db1 = QSqlDatabase::addDatabase("QODBC","remote");
>
> Both the databases are getting open, which I am checking with db.open.
> But once I try to execute query for any database, (eg. create table),
> I am getting the error "QSqlQuery::exec: database not open"
>
> If I work with just once database, I am not getting the error and can
> comfortably execute queries within that database.
>
> Why is this happening ? How can I comfortably work with more than one
> database in an application ?
>
Just a guess:
With variable names such as "db" and "db1", there is most likely a typo
somewhere and you are overwriting one of these variables by assigning to
it twice?
You could use "db_local" and "db_remote" instead. If you are using a
modern IDE such as QtCreator or VS, you can use the auto-completion
feature...
More information about the Qt-interest-old
mailing list