Qt database
-
wrote on 11 Aug 2011, 14:09 last edited by
hiii...this is my first database app using Qt and i dont know what is wrong any help??
@#include <QtCore/QCoreApplication>
#include <QtSql>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
//127.0.0.1
QString servername = "localhost\SQLEXPRESS";
QString dbname = "MyDatabase";QSqlDatabase db = QSqlDatabase::addDatabase("QODBC"); db.setConnectOptions(); QString dsn = QString("DRIVER={SQL Native Client};SERVER=%1;DATABASE=%2;Trusted_Connection=Yes;").arg(servername).arg(dbname); db.setDatabaseName(dsn); if(db.open()) { qDebug()<<"connected finallyyyyyyyyyy :D:D:D:D"; }else{ qDebug()<<db.lastError().text(); qDebug() << QSqlDatabase::drivers(); } return a.exec();
}
@ -
wrote on 11 Aug 2011, 14:14 last edited by
And the output is?
-
wrote on 11 Aug 2011, 16:07 last edited by
"[Microsoft][ODBC Driver Manager]Data source name not found and no default driver specified QODBC3:Unable to connect"
-
wrote on 11 Aug 2011, 16:54 last edited by
Seems that your data source isn't set up properly. Can you access it from other software (e.g. MS Access Or OO) through ODBC?
-
wrote on 11 Aug 2011, 18:30 last edited by
ok thx alot...what will be the server name if i will use MS access??...excuse my bad question I am a DB beginner ;)
-
wrote on 11 Aug 2011, 18:34 last edited by
"This":http://www.connectionstrings.com/ will help you.
-
wrote on 11 Aug 2011, 18:35 last edited by
thank you very much =)
1/7