Results 1 to 3 of 3

Thread: Qt ODBC data source not found

  1. #1
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Qt ODBC data source not found

    Hello all,
    Currently i am working on a project in which i have to connect MySQL database through ODBC.
    Operating system : CentOS

    the problem i am facing is, whenever i execute the aplication it says

    [unixODBC][Driver Manager]Data source name not found, and no default driver specified QODBC3: Unable to connect

    Qt Code:
    1. database_manager_ = QSqlDatabase::addDatabase("QODBC3", "test_qt");
    2. database_manager_.setDatabaseName("Server=localhost;Database=test_qt;user=karan;password=karan;");
    3. database_manager_.setHostName("localhost");
    4. database_manager_.setUserName("karan");
    5. database_manager_.setPassword("karan");
    To copy to clipboard, switch view to plain text mode 

    searched a lot on google but not found any successfull solution.
    Please help..

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt ODBC data source not found

    On Linux you should use the MySql plugin not ODBC.

    If you must use ODBC for some odd reason then you need to provide a valid ODBC DSN in the call to setDatabaseName(), which is the error message you are getting. You define a DSN using the tools provided with unixODBC. Of course you also need a suitable MySQL ODBDC driver.
    Last edited by ChrisW67; 29th June 2013 at 08:47.

  3. The following user says thank you to ChrisW67 for this useful post:

    karankumar1609 (1st July 2013)

  4. #3
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Talking Re: Qt ODBC data source not found

    I have changed my DSN and now another problem occured:
    Qt Code:
    1. database_manager_ = QSqlDatabase::addDatabase("QODBC3", "test_qt");
    2. database_manager_.setDatabaseName("MySQL_Test");
    3. // database_manager_.setDatabaseName("Driver={MySQL_Test};USER=karan;Password=karan;SERVER=localhost;");
    4. database_manager_.setHostName("localhost");
    5. database_manager_.setUserName("karan");
    6. database_manager_.setPassword("karan");
    To copy to clipboard, switch view to plain text mode 

    when i execute the above code it gives me :
    Qt Code:
    1. ("QSQLITE", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3")
    2. Driver available : true
    3. Database opened successfully
    4. "MySQL_Test"
    5. QSqlQuery::exec: database not open
    6. createEmployeeTable : false
    7. QSqlQuery::exec: database not open
    8. getProfileRecords EXEC : false
    To copy to clipboard, switch view to plain text mode 

    Hopefully that means it connects to the DSN and database got opened but why it gives error as "database not open" when i want to create a table.

    what is the problem here please help...


    Added after 1 32 minutes:


    :P

    I got the solution... :
    Just missed to pass the QSqlDatabase object in QSqlQuery ...

    Qt Code:
    1. QSqlQuery query(database_object);
    2. query.exec("SELECT * FROM table_name");
    To copy to clipboard, switch view to plain text mode 
    Last edited by karankumar1609; 1st July 2013 at 07:37.

Similar Threads

  1. Replies: 1
    Last Post: 20th March 2013, 18:25
  2. source code for odbc driver or MySql driver in arm-embedded-linux
    By sattu in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 24th January 2011, 10:11
  3. Empty SQL Data from ODBC/FreeTDS
    By dentharg in forum Qt Programming
    Replies: 0
    Last Post: 9th November 2009, 07:50
  4. remote ODBC data source
    By mchara in forum Qt Programming
    Replies: 7
    Last Post: 10th December 2007, 10:39
  5. Connecting to an ODBC Data Source
    By kikapu in forum Newbie
    Replies: 9
    Last Post: 25th June 2007, 12:18

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.