PDA

View Full Version : connection is not open



emental86
28th November 2008, 13:27
Hello, first I'm sorry for my english.

So I try to connect to database trought QT4, but it doesn't work. Program is compiled, and I can run it, but the connection is not open. Do you know where is the problem?

Code:


#include <QtSql>
#include <iostream>
#include <QApplication>
#include <QSqlDatabase>

int main(int argc, char *argv[]){
QCoreApplication a(argc, argv);
// server_name, db_name, user_name and password isn't real because of privacy
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setHostName("server_address");
db.setDatabaseName("db_name");
db.setUserName("user_name");
db.setPassword("password");
bool ok = db.open();
if(ok){
std::cout << "Connect...";
}else{
std::cout << "Not connect!"
}
return 0;
}

When I run the programm I get: Not connect!
Can anyone help me please?

caduel
28th November 2008, 14:42
* try printing the error message: QSqlDatabase::lastError()
* also, check your console for errors: could the db driver plugin be found/loaded?

HTH

emental86
1st December 2008, 21:46
thx, now it says: [unixODBC][Driver Manager]Data source name not found, and no default driver specified QODBC3: Unable to connect

Do anyone know what cas I do?

wysota
1st December 2008, 22:04
You have to configure an ODBC connection.

http://www.unixodbc.org/doc/