PDA

View Full Version : Connection with MS SQL



manish_pesit
28th August 2006, 11:50
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.

Zatraz
30th August 2006, 22:45
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.

manish_pesit
4th September 2006, 12:59
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?

Zatraz
4th September 2006, 14:51
You will connect to SQL Server using FreeTDS plugin with something like this:



// Note: QT4
QSqlDatabase db = QSqlDatabase::addDatabase("QTDS7");
db.setDatabaseName(database);
db.setHostName(host);
db.setUserName(user);
db.setPassword(pass);

setenv("TDSVER", "8.0", 1);
setenv("TDSPORT", dbport, 1); //! setPort() does not work properly

if (!db.open())
{
qWarning("Erro opening database connection: " + db.lastError().text());
return 1;
}

manish_pesit
13th September 2006, 08:47
You will connect to SQL Server using FreeTDS plugin with something like this:



// Note: QT4
QSqlDatabase db = QSqlDatabase::addDatabase("QTDS7");
db.setDatabaseName(database);
db.setHostName(host);
db.setUserName(user);
db.setPassword(pass);

setenv("TDSVER", "8.0", 1);
setenv("TDSPORT", dbport, 1); //! setPort() does not work properly

if (!db.open())
{
qWarning("Erro opening database connection: " + db.lastError().text());
return 1;
}


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