Same problem. can anyone help?
Same problem. can anyone help?
Added after 5 minutes:
This is my code:
int main(int argc, char *argv[]) {
QSettings& settings = *pSettings;
QString connectionTemplate
= "Driver={SQL Server};Server=%1;Database=%2;Uid=%3;Pwd=%4;";
QString server
= settings.
value("DBProductsServer").
toString();
QString database
= settings.
value("DBProductsDatabase").
toString();
QString user
= settings.
value("DBProductsUser").
toString();
QString pass
= settings.
value("DBProductsPass").
toString();
QString connectionString
= connectionTemplate
.arg(server)
.arg(database)
.arg(user)
.arg(pass);
db.setDatabaseName(connectionString);
if (db.open() ) {
std::cout << "DB Verbindung vorhanden" << std::endl;
while (query.next()) {
std::cout << query.value(0).toString().toStdString() << std::endl;
}
} else {
std::cout << error.databaseText().toStdString() << std::endl; ;
std::cout << error.driverText().toStdString() << std::endl; ;
std::cout << "Konnte keine DB Verbindung aufbauen" << std::endl;
}
return 0;
}
int main(int argc, char *argv[]) {
QSettings* pSettings = new QSettings(QDir::currentPath() + "/" + CONFIG_FILE, QSettings::IniFormat);
QSettings& settings = *pSettings;
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
QString connectionTemplate = "Driver={SQL Server};Server=%1;Database=%2;Uid=%3;Pwd=%4;";
QString server = settings.value("DBProductsServer").toString();
QString database = settings.value("DBProductsDatabase").toString();
QString user = settings.value("DBProductsUser").toString();
QString pass = settings.value("DBProductsPass").toString();
QString connectionString = connectionTemplate
.arg(server)
.arg(database)
.arg(user)
.arg(pass);
db.setDatabaseName(connectionString);
if (db.open() ) {
std::cout << "DB Verbindung vorhanden" << std::endl;
QSqlQuery query("SELECT * FROM dbo.BOM");
while (query.next()) {
std::cout << query.value(0).toString().toStdString() << std::endl;
}
} else {
QSqlError error = db.lastError();
std::cout << error.databaseText().toStdString() << std::endl; ;
std::cout << error.driverText().toStdString() << std::endl; ;
std::cout << "Konnte keine DB Verbindung aufbauen" << std::endl;
}
return 0;
}
To copy to clipboard, switch view to plain text mode
After execution I see the following error messages:
"QODBCDriver::disconnect: Unable to disconnect datasource" Error: " [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionClose (closesocket()). [Microsoft][ODBC SQL Server Driver][DBNETLIB]"
"QODBCDriver::cleanup: Unable to free connection handle" Error: " [Microsoft][ODBC Driver Manager] Fehler in der Funktionsreihenfolge"
"QODBCDriver::cleanup: Unable to free environment handle" Error: "[Microsoft][ODBC Driver Manager] Fehler in der Funktionsreihenfolge "
"QODBCDriver::disconnect: Unable to disconnect datasource" Error: " [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionClose (closesocket()). [Microsoft][ODBC SQL Server Driver][DBNETLIB]"
"QODBCDriver::cleanup: Unable to free connection handle" Error: " [Microsoft][ODBC Driver Manager] Fehler in der Funktionsreihenfolge"
"QODBCDriver::cleanup: Unable to free environment handle" Error: "[Microsoft][ODBC Driver Manager] Fehler in der Funktionsreihenfolge "
To copy to clipboard, switch view to plain text mode
Bookmarks