PDA

View Full Version : QSqlDatabase sql server



william.cy
8th July 2013, 18:13
I have started in QT and sql server : I have read a lot of examples to do my connection but no one works
here ir my code :




/*db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("DRIVER={SQL Server};Trusted_Connection=Yes");
db.setDatabaseName("BD_83_MATRICULA");
db.setHostName("localhost");
db.setUserName("Bytes");*/
db = QSqlDatabase::addDatabase("QODBC");

QString dns = "DRIVER={SQL Native Client};SERVER=localhost;DATABASE=BD_83_MATRICULA; UID=BYTES;Trusted_Connection=Yes;";
db.setDatabaseName(dns);

if(!db.open())
{
qDebug() << db.lastError().text();
QMessageBox::critical(0, qApp->tr("mensaje"),
qApp->tr("No conecto\n"
"Presione cancelar."),QMessageBox::Cancel);
}
else
{
QMessageBox::information(0, "Mensaje","Conecto");
}


and the error says:

"[Microsoft][Administrador de controladores ODBC] No se encuentra el nombre del origen de datos y no se especificó ningún controlador predeterminado QODBC3: Unable to connect"

i need the help :D please

ChrisW67
8th July 2013, 22:53
Google Translation

[Microsoft] [ODBC Driver Manager] Can not find the data source name and no default driver specified
QODBC3: Unable to connect
I would start by either leaving the trusted connection option out (using SQL Server authentication), or leaving the uid and pwd options without values (forcing a trusted connection)
http://support.microsoft.com/kb/194641