PDA

View Full Version : Second use of a QSqlDatabase instance in a QSqlQuery fails.



ecurren
16th June 2011, 18:06
Hello all,
Please accept my appologies if this question has already been asked and answered. In my search of the posts, I did not find this issue, however if it exists, please refer me to the post.

We are writing an application where, when the app initializes, an instance of QSqlDatabase is created, a database added via the static addDatabase function. The connection then opened, and is verified as open. The database uses the default connection rather than naming it.

In later classes we are creating instances of QSqlQuery and running queries against the database. We use on instance of QSqlQuery for each SQL statement that we run as reuse of a query object is not practical given the design of the application.

The problem we are encountering is that the first query works, however subsequent QSqlQuery instances which are created are failing with a message similar to “The database could not be opened” even though we have not called database.close(). The failure is encountered quickly. Depending on whether we add the SQL to the QSqlQuery constructor or defer the SQL to a prepare statement, the failure happens within one of these two lines.

We know that these are all good SQL queries as we have tested them outside of the application.

Thank you for your help with this

wysota
16th June 2011, 20:13
Please prepare a minimal compilable example reproducing the problem.