Results 1 to 16 of 16

Thread: Qsql and connection

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Mar 2013
    Posts
    45
    Thanks
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qsql and connection

    thanks a lot .

    Why do I get the error message when I compile ?
    QsqlDatabase: QODBC driver not loaded
    QSqlDataase : available drivers:QSQLITE
    my code :
    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QtSql>
    3. #include <QDebug>
    4. int main(int argc, char *argv[])
    5. {
    6. QCoreApplication a(argc, argv);
    7. QString servername = "LOCALHOST\\SQLEXPRESS" ;
    8. QString dbname = "test";
    9. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    10. db.setConnectOptions();
    11. QString dsn = QString("DRIVER={SQL Native Client};SERVER=%1;DATABASE=%2;Trusted_Connection=Yes;").arg(servername).arg(dbname);
    12. db.setDatabaseName(dsn);
    13.  
    14. if(db.open())
    15. {
    16. qDebug() << "Opene.." ;
    17. }
    18.  
    19. else
    20. qDebug() << "Not Opene.." << db.lastError();
    21.  
    22. return a.exec();
    23. }
    To copy to clipboard, switch view to plain text mode 

    Microsoft SQL Server 2008
    Windows 7
    Last edited by smemamian; 5th April 2013 at 09:27.

Similar Threads

  1. Replies: 0
    Last Post: 11th November 2011, 19:18
  2. Using auto_increment in QSql
    By SykeS in forum Newbie
    Replies: 3
    Last Post: 21st May 2010, 07:13
  3. Replies: 1
    Last Post: 2nd April 2010, 06:42
  4. connection with qsql module
    By adamatic in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2009, 10:38
  5. QSql error
    By renjithmamman in forum Qt Programming
    Replies: 4
    Last Post: 20th December 2006, 10:28

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
  •  
Qt is a trademark of The Qt Company.