Results 1 to 6 of 6

Thread: postgresql connection network

  1. #1
    Join Date
    Mar 2012
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default postgresql connection network

    hi everyone,
    i want to make a connection between a qt program installed in a client machine and a postgresql database stored on a server
    this is the program i wrote

    #include <QtGui/QApplication>
    #include<QtSql>
    #include<QtDebug>
    #include "mainwindow.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    QSqlDatabase db =QSqlDatabase::addDatabase("QODBC");

    db.setHostName("10.9.173.168"); //this ip adress is the adress of the server machine and i used it in odbc and i have connection succeful
    db.setDatabaseName("khaw");
    db.setPassword("khawla");
    db.setUserName("postgres");
    db.setPort(5432);

    if(db.open())
    {
    qDebug() <<"opened" ;

    db.close();
    }
    else
    {
    qDebug() << db.lastError().text();
    }
    MainWindow w;
    w.show();

    return a.exec();
    }
    but i still have the error "[Microsoft][Gestionnaire de pilotes ODBC] Source de données introuvable et nom de pilote non spécifié QODBC3: Unable to connect"
    which is in english [Microsoft] [ODBC Driver Manager] Data source name not found and no default driver specified
    in odbc i wrote this:
    data source:khaw
    database:basee
    server:10.9.173.168
    user nameosgres
    ssl mode:disable
    port:5432
    password:khawla
    can you tell me what i should do to connect
    thanks for your reply

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: postgresql connection network

    You did connect.
    Error message you're getting comes from server.

    Besides, I think you're setting database name wrong, try 'basee' instead of 'khaw'.

    If you google for the error, many people say it happens when you don't use dns to connect to server.
    Maybe that's it?

  3. #3
    Join Date
    Mar 2012
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: postgresql connection network

    i didn't really understand what's the error that you mean
    can you explain more
    thanks for your reply

  4. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: postgresql connection network

    [Microsoft] [ODBC Driver Manager] Data source name not found and no default driver specified
    Google for it.
    There's quite few people having this issue.

    Using IP instead of hostname seems to be one of the reasons for getting this error.

    Did you check if using 'basee' as the database name changes anything? From what you've posted above seems that it may be relevant.

  5. #5
    Join Date
    Mar 2012
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: postgresql connection network

    in setdatabasename we put the odbc data source not the name of database
    and if i put localhost it's just my computer and not in network

  6. #6
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: postgresql connection network

    From the documentation:
    For the QODBC driver, the name can either be a DSN, a DSN filename (in which case the file must have a .dsn extension), or a connection string.

    For example, Microsoft Access users can use the following connection string to open an .mdb file directly, instead of having to create a DSN entry in the ODBC manager:

    ...
    db = QSqlDatabase::addDatabase("QODBC");
    db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=myaccessfile.mdb");
    if (db.open()) {
    // success!
    }
    ...

Similar Threads

  1. QT to Postgresql connection
    By KeithN in forum Newbie
    Replies: 28
    Last Post: 28th November 2013, 16:33
  2. Check network connection
    By sophister in forum Qt Programming
    Replies: 8
    Last Post: 3rd September 2012, 12:00
  3. connection QT with postgresql
    By khadija123 in forum Qt Programming
    Replies: 6
    Last Post: 31st March 2012, 21:09
  4. Replies: 0
    Last Post: 1st December 2010, 20:21
  5. QFtp with no network connection
    By josepvr in forum Qt Programming
    Replies: 0
    Last Post: 19th November 2008, 15:03

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.