Results 1 to 2 of 2

Thread: Second use of a QSqlDatabase instance in a QSqlQuery fails.

  1. #1
    Join Date
    Jun 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Second use of a QSqlDatabase instance in a QSqlQuery fails.

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Second use of a QSqlDatabase instance in a QSqlQuery fails.

    Please prepare a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 1st August 2010, 15:06
  2. QSqlDatabase::open() fails with QODBC
    By grzywacz in forum Qt Programming
    Replies: 4
    Last Post: 7th April 2010, 04:27
  3. Replies: 14
    Last Post: 16th January 2009, 09:11
  4. Only let one instance of the application run
    By chrisdsimpson in forum Newbie
    Replies: 1
    Last Post: 9th April 2008, 22:30
  5. Batch update fails with QSqlQuery
    By William Wilson in forum Qt Programming
    Replies: 2
    Last Post: 20th July 2007, 16:36

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.