Results 1 to 5 of 5

Thread: Connection with MS SQL

  1. #1
    Join Date
    Aug 2006
    Posts
    3
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Connection with MS SQL

    Hello everybody,
    i am creating an application for which I want to use Qt and MS SQL. I want Qt desginer which is running on linux to access MS SQL server which is on windows machine. if any one has done this then plz help me.

  2. #2
    Join Date
    Mar 2006
    Posts
    9
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Connection with MS SQL

    Hi,

    I did a proxy that connect to a SQL Server. I used the FreeTDS SQL driver (http://www.freetds.org/) compiled with Qt (using the --qt-sql-tds configure directive). I fallowed Qt instructions and it worked fine.

    The proxy uses a store procedure to query data, so I only read the DB (I did not test write queries). I used both Qt3 and Qt4, but with Qt3 the program leaked when the query failed in some cases. At the beginning I thought that was something wrong with my code, but when I ported it to Qt4 the leak was gone. I tried debug it with valgrind, but the log generated is really big and sometimes enigmatic.

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

    manish_pesit (4th September 2006)

  4. #3
    Join Date
    Aug 2006
    Posts
    3
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Connection with MS SQL

    Quote Originally Posted by Zatraz
    Hi,

    I did a proxy that connect to a SQL Server. I used the FreeTDS SQL driver (http://www.freetds.org/) compiled with Qt (using the --qt-sql-tds configure directive). I fallowed Qt instructions and it worked fine.

    The proxy uses a store procedure to query data, so I only read the DB (I did not test write queries). I used both Qt3 and Qt4, but with Qt3 the program leaked when the query failed in some cases. At the beginning I thought that was something wrong with my code, but when I ported it to Qt4 the leak was gone. I tried debug it with valgrind, but the log generated is really big and sometimes enigmatic.
    I configured that one with unixODBC and freeTDS. from command prompt I am able to create , read and all basic operations to MS SQL. But in order to make use it in Qt program what will be the driver name?

  5. #4
    Join Date
    Mar 2006
    Posts
    9
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Connection with MS SQL

    You will connect to SQL Server using FreeTDS plugin with something like this:

    Qt Code:
    1. // Note: QT4
    2. QSqlDatabase db = QSqlDatabase::addDatabase("QTDS7");
    3. db.setDatabaseName(database);
    4. db.setHostName(host);
    5. db.setUserName(user);
    6. db.setPassword(pass);
    7.  
    8. setenv("TDSVER", "8.0", 1);
    9. setenv("TDSPORT", dbport, 1); //! setPort() does not work properly
    10.  
    11. if (!db.open())
    12. {
    13. qWarning("Erro opening database connection: " + db.lastError().text());
    14. return 1;
    15. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Zatraz; 4th September 2006 at 17:48.

  6. #5
    Join Date
    Aug 2006
    Posts
    3
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Connection with MS SQL

    Quote Originally Posted by Zatraz
    You will connect to SQL Server using FreeTDS plugin with something like this:

    Qt Code:
    1. // Note: QT4
    2. QSqlDatabase db = QSqlDatabase::addDatabase("QTDS7");
    3. db.setDatabaseName(database);
    4. db.setHostName(host);
    5. db.setUserName(user);
    6. db.setPassword(pass);
    7.  
    8. setenv("TDSVER", "8.0", 1);
    9. setenv("TDSPORT", dbport, 1); //! setPort() does not work properly
    10.  
    11. if (!db.open())
    12. {
    13. qWarning("Erro opening database connection: " + db.lastError().text());
    14. return 1;
    15. }
    To copy to clipboard, switch view to plain text mode 
    If I am using the above code then it throws an error :

    QSqlDatabase: QTDS7 driver not loaded
    QSqlDatabase: available drivers: QODBC3

    Can you tell me from where I will get QTDS7 driver?

    thanks

Similar Threads

  1. connection problem
    By mhoover in forum Qt Programming
    Replies: 1
    Last Post: 7th July 2006, 22:14
  2. Replies: 3
    Last Post: 22nd June 2006, 16:27
  3. How do I keep the client connection open ?
    By probine in forum Newbie
    Replies: 2
    Last Post: 25th March 2006, 19:06
  4. connect to sql server
    By raphaelf in forum Qt Programming
    Replies: 15
    Last Post: 27th February 2006, 18:06
  5. Can I launch a dial-up connection in Windows?
    By gtthang in forum Qt Programming
    Replies: 3
    Last Post: 9th February 2006, 12:32

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.