thanks a lot .
Why do I get the error message when I compile ?
QsqlDatabase: QODBC driver not loaded
QSqlDataase : available drivers:QSQLITE
my code :
#include <QCoreApplication>
#include <QtSql>
#include <QDebug>
int main(int argc, char *argv[])
{
QString servername
= "LOCALHOST\\SQLEXPRESS" ;
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() << "Opene.." ;
}
else
qDebug() << "Not Opene.." << db.lastError();
return a.exec();
}
#include <QCoreApplication>
#include <QtSql>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString servername = "LOCALHOST\\SQLEXPRESS" ;
QString dbname = "test";
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() << "Opene.." ;
}
else
qDebug() << "Not Opene.." << db.lastError();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Microsoft SQL Server 2008
Windows 7
Bookmarks