Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more: , +
i have a server of windows server 2003 and its IP on my local network is 192.168.1.220

this server has SOL server 2005 express edition installed with user name sa and password amir

this SQL server has a database called amir

i want to connect to it from a Linux client on the same network

SQL server service using port 1617 on my server and i used this port to connect to the server using java

now i want to use QT C++ but i tried alot but my code don't want to work

this is my code
C++
#include <QtCore/QCoreApplication>
#include<QWidget>
#include<ostream>
#include<iostream>
#include<QFile>
#include<QTime>
#include <stdio.h>
#include <QTextStream>
#include<QSqlDatabase>
#include<QSqlDriver>
using namespace std;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    bool test=db.isValid();//true
    test=db.isDriverAvailable("QODBC");//true
    db.setHostName("192.168.1.220\\SQLEXPRESS");
    db.setDatabaseName("DRIVER={SQL Server};SERVER=192.168.1.220\\SQLEXPRESS:1617;DATABASE=amir");
    db.setUserName("sa");
    db.setPassword("amir");
    db.setPort(1617);
    test=db.isValid();//true
    if(!db.open())
    {
        cout<<endl<<"not connected"<<endl;
        QString error=db.lastError().text();
        cout<<error.toLocal8Bit().data();
        return false;
    }
    else
        cout<<endl<<"connected"<<endl;
         return true;

}



every time i try this it out "not connected"

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

using this parameters i can connect using java

so what is the wrong here? and if there is another fasting way to connect to the SQL server using qt c++ than ODBC driver please tell me
Posted
Updated 29-Sep-12 23:23pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900