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[]){
// server_name, db_name, user_name and password isn't real because of privacy
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;
}
#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;
}
To copy to clipboard, switch view to plain text mode
When I run the programm I get: Not connect!
Can anyone help me please?
Bookmarks