Answer the question
In order to leave comments, you need to log in
What is wrong with the database connection?
Through the qt application I'm trying to connect to the database. Writes Data source not found, can it be programmatically specified O_o?
Here is the text of the function that connects:
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setHostName("USER-PC\SQLPROTUPIN");
db.setDatabaseName("hospital");
db.setUserName("sa");
db.setPassword("sasa178");
bool ok = db.open();
QTableWidgetItem * item = new QTableWidgetItem();
if (!ok) {
item->setText("Cannot open database:"+db.lastError().text());
}else item->setText("1");
ui->tableWidget->setItem(0,0,item);
Answer the question
In order to leave comments, you need to log in
Connected to the database like this
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC","connection");
QString path = "AttachDbFilename=C:\\Program Files\\Microsoft SQL Server\\MSSQL11.SQLPROTUPIN\\MSSQL\\DATA\\hospital.mdf";
db.setDatabaseName("DRIVER={SQL Server}; Server=.\\SQLPROTUPIN;" + path + ";Database=hospital; Trusted_Connection=Yes;");
bool ok = db.open();
As far as I remember, you need to put the database driver next to the exe. dlls. And write there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question