Need to connect C++ application with web database

Asked By 20 points N/A Posted on -
qa-featured

I am a web designer and also a good programmer.I designed an application in c++ using Microsoft visual studio. It has .exe format.Now i want to use my application in web database.It is basically a spell check app and I want to link it to my database.Anyone know how to do this please answer.

SHARE
Answered By 0 points N/A #150494

Need to connect C++ application with web database

qa-featured

Hello Allan!

There are several ways for you to connect database and your C++ application. Adding few sets of codes is a very easy task. Here I will use Sql Server database connected to it. We will not require any connection setup here, we are going to call the database using the usual set of commands. This also works with VB applications.

#include <QtSql>

int main(int argc, char *argv[])

{

    ….

    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");

    db.setDatabaseName("DRIVER={SQL Server};Server=SERVER NAME;Database=YOUR DB NAME;User ID=admin;Password=admin;Trusted_Connection=yes;");

    if(!db.open())

    {

       qDebug() << db.lastError().text();

       return 0;

    }

    ….

}

Explanation:

The first thing that you need to do is to set up your Sql Server. If you already installed the server in you computer and haven’t tried it yet, I am sure that your Username is “admin” and Password is “admin” also. On lines 8 and 9, you see the server=YOUR SERVER NAME. You just have to open and check for the server name in your Sql Server. Replace that with the server name and same thing that you have to do with username and password. This is confirmed a working code and have gone through this many times and it is durable. I have tried to run some queries with this in multiple computers though, if there’s an instance that your queries in multiple computers will have same time of query, the other computer will not show data, you just have to repeat it again.

Related Questions