PDA

View Full Version : QSqlDatabase: QODBC driver not loaded



sattu
21st January 2011, 11:11
hi everyone ,
I want to connect remotely to ms sql server through an application.For this ODBC is required.
I followed the following lines:




It is recommended that you use unixODBC. You can find the latest version and ODBC drivers at http://www.unixodbc.org. You need the unixODBC header files and shared libraries.

Tell qmake where to find the unixODBC header files and shared libraries (here it is assumed that unixODBC is installed in /usr/local/unixODBC) and run make:

cd $QTDIR/src/plugins/sqldrivers/odbc
qmake "INCLUDEPATH+=/usr/local/unixODBC/include" "LIBS+=-L/usr/local/unixODBC/lib -lodbc"
make




But i am getting an error :- QSqlDatabase: QODBC driver not loaded

My pc is linux 64 bit (fedora -11).I am using qt 4.6.


My code is :





QString conn = QString::fromLocal8Bit("DRIVER={SQL SERVER};SERVER=192.168.10.82\\SQLExpress;DATABASE= master;Uid=sa;Pwd=[]");
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "MainDBConnection");
db.setDatabaseName(conn);
db.setUserName("essl");
db.setPassword("essl");
bool flag = db.open();




plz tell me how to connect with server .
Is there anything extra to add plugin .
or a odbc driver is required

certqt
22nd January 2011, 12:40
It is recommended that you use unixODBC. You can find the latest version and ODBC drivers at http://www.unixodbc.org. You need the unixODBC header files and shared libraries.

Tell qmake where to find the unixODBC header files and shared libraries (here it is assumed that unixODBC is installed in /usr/local/unixODBC) and run make:

cd $QTDIR/src/plugins/sqldrivers/odbc
qmake "INCLUDEPATH+=/usr/local/unixODBC/include" "LIBS+=-L/usr/local/unixODBC/lib -lodbc"
make

Did you build the plugin successfully? If not you can open it as a normal Qt Project (File->Open File or Project) and you can find the .pro in $QTDIR/src/plugins/sqldrivers/odbc as stated.


But i am getting an error :- QSqlDatabase: QODBC driver not loaded

Is there a second line to the error, something like


Available drivers are: ...

If ODBC is in the list of available plugins then the problem is because the unixODBC driver is not installed or set up correctly. On the other hand if the ODBC driver is not in the list then it means that either you haven't built the plugin properly or your application isn't finding it. I had the latter problem with the IBASE plugin which was solved by setting the following environment variable in the project's build environment:


Set QT_PLUGIN_PATH to /home/xxxx/qtsdk-2010.04/qt/plugins/

This is because (on openSuSE at least) the QT_PLUGIN_PATH is set to somewhere in the users .kde folder

This will get you up and running, but of course you need to do something smarter when it comes to distributing your application ;)