Crash when opening a SQL Server or Access database (OS X)
-
Hi everyone !
I have a embarrassing problem with my application : I have developed a little program to connect and make request to different kind data bases (SQLite - SQL Server and MS Access). This works fine with Windows 10 but now I have to run it with OS X (with the same code).
The thing is that I never used a Mac before, so I'm a little bit lost... Like Windows, I have built the ODBC plugin and put the generated files (.a and .prl) in my {debug}/sqldrivers folder. I have also installed unixODBC.
Now the problem : when I run my application, it crashes when I call bd.open() for SQL Server and MS Access (SQLite works fine). It says that "This application has stopped suddenly" with no error message or anything that could help..
My code is the same on Windows and Mac (Qt (5.6) and QtCreator (3.6.1) too), that's why I don't understand why it doesn't work on Mac. I presume that my problem has a link with the ODBC driver. (db.isDriverAvailable("QODBC"); returns true)If someone has a clue to resolve it, I am interested !
(and sorry if I have made mistakes, I'm french and I have some difficulties with tenses)
Thank you !
-
Hi the_ !
Thanks for your answer, here is the code to connect to MS Access :QString tmp = QFileDialog::getOpenFileName(0, "Ouvrir une base de données", "", "Microsoft Access Driver (*.mdb, *.accdb)"); if(!tmp.isEmpty()) //Un fichier a ete selectionne { base = QSqlDatabase::addDatabase("QODBC"); base.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};FIL={MSAccess};DBQ=" + tmp + ";"); if(base.open()) { QMessageBox::information(0, "Information", "Base chargée avec succès."); } else { QMessageBox::critical(0, "Attention", "Échec de l'ouverture de la base Access : \n" + base.lastError().text()); return; } } else { QMessageBox::information(0, "Attention", "Pas de base selectionnée."); }
and for SQL Server :
QString connectionTemplate = "DRIVER={SQL SERVER};SERVER=%1;DATABASE=%2;"; QString connectionString = connectionTemplate.arg(server).arg(dbName); base = QSqlDatabase::addDatabase("QODBC", connectionName); base.setDatabaseName(connectionString); base.setUserName(user); base.setPassword(password); if(base.open()) { QMessageBox::information(0, "Information", "Base chargée avec succès."); } else { QMessageBox::critical(0, "Attention", "Échec de l'ouverture de la base SQL Server : \n" + base.lastError().text()); return; }
Those codes works on Windows but they crash on both lines
if(base.open())
on Mac, so the program can't reach base.lastError()
-
Hi, even though you have successfully installed Qt's QODBC plugin on your Mac, you also need the database driver (the file that the QODBC plugin wants to load). Without it, you will get the crash.
In Windows these database driver files are usually already installed, but not so on the Mac :-(
I have successfully connected to an MS SQLServer, by first downloading/installing unixODBC (same as you have done) and then also downloading/installing FreeDTS
For an Access driver, I googled just now, and could only find a driver for 35 US$ see this blog post -
Hi !
Thanks for your response ! That makes the problem clearer :)
I have took a look to Free TDS, it seems to be hard to install but I will try ! I will tell you if it works.
Is it me or you must pay for most of things on the Mac ? I don't think i will try to connect an Acces base if I have to pay -
thanks for your help, I have tried to edit my odbc.ini the Mac refused to save the file... That's why I gave up.
As an intern, it's my tutor training who said to me to look at a native component. But if I can't find any solution I will come back to the first idea :)