Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Creating odbc plugin
Hi, I am trying to connect a MS Sql server to my application using the ODBC driver. The problem I have is I do not know what I am doing!
Could you please tell me step by step, what I need to do to connect. I have read the documentation but it is not exactly clear. Please forgive my ignorance :)
The ODBC driver is build by default, so there is nothing special you need to do to get it to work. Do you already have ODBC itself setup correctly? Did you setup an ODBC data source (you do that in the OS, not using Qt) for your database?
Hi Thanks for replying....
I am using a host for my database and I have set an ODBC connection. The problem is how to get connected to the database. I have very little experience with QT and have read the docs about creating a plugin etc. If this is enabled by default, what do I need to do in my application to connect. When I use the addDatabase function, I get an error 'collect2: Id returned 1 exit status. I was assuming this was because the ODBC driver is not installed. What header files should I be using etc?
You should add this to your .pro file, to start with:
QT += sql
That should take care of the linking error.
Thank you, this seems to have solved the linking error. Is there anything else I need to do, or should that be it? Do I need to include the Sqlt header file and the one for odbc?
You only need to include the header files for the classes that you use directly at the place where you use it. That is, you will probably need to include these at some point (not necessarily all at the same place):
//and perhaps also:
thanks for your help Andre. If I run into any more probs I will be back :)
Ok, still got problems.....lol
If I create an odbc on a remote host, how do I connect my app to it? Any help appreciated.
How is having problems something to 'lol' about?
Anyway, you need to set the odbc connectionstring as the database name.
Where can I find info about the connection string format. All I have found at the moment is a little about using the DNS connection and setting the following:
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setHostName( <What goes here? > );
db.setDatabaseName( < what goes here?> );
Is this the right way to connect? Can I use a DNS-less connection string instead and if so how?
I have set up a ODBC source on my remote server but have no idea how to connect to it....
I wont lol again, not yet anyway!