标签:
#include <QCoreApplication>
#include <QtSql>
#include <QtDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString servername="THINKPAD-PC"; //LOCALHOST
QString dbname="AdventureWorks2008R2";
QSqlDatabase db=QSqlDatabase::addDatabase("QODBC");
db.setConnectOptions();
QString dsn=QString("DRIVER={SQL SERVER};SERVER=%1;DATABASE=%2;Trusted_Connection=Yes;").arg(servername).arg(dbname);
db.setDatabaseName(dsn);
if(db.open())
{
qDebug()<<"opened";
db.close();
}
else
{
qDebug()<<"ERROR="<<db.lastError().text();
}
return a.exec();
}
标签:
原文地址:http://www.cnblogs.com/hnu-wt/p/4305970.html