PDA

View Full Version : Access Exsisting MSSQL databasse



deepal_de
13th July 2011, 05:11
How can i get data from existing MSSQL database to a Qt applicaion.. im using sql with Qt for the first time....so
if u can,please include a complete example code.. thanks :)

mcosta
13th July 2011, 05:36
You have to use a QODBC driver.

for example code see the official documentation

deepal_de
13th July 2011, 06:55
WebDataBase is a DB thats in my MSSQLEXPRESS sever..



QSqlDatabase qDb = QSqlDatabase::addDatabase("QODBC");
qDb.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=WebDataBase.mdb");
if (qDb.open())
{
QMessageBox::information(NULL,"Message", "DB open");
}
else
{
QMessageBox::information(NULL,"Message", "DB close");
}



this doesn't work!
how to chage the "qDb.setDatabaseName" to work with MSSQLEXPRESS

mcosta
13th July 2011, 07:51
I never used MSSQL,

however you have to set a correct ODBC configuration string (you used a Access Driver)

I found this


"Driver={SQLServer};Server=Your_Server_Name;Databas e=Your_Database_Name;Uid=Your_Username;Pwd=Your_Pa ssword;"