QT Login Timeout expired QODBC3:Unable to connect ERROR

696 Views Asked by At

I am trying to connect my SQL Server to the qt project with this code

QString servername = "OLI-PC";

QString dbname = "Translator";

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

db.setConnectOptions();

qDebug()<<"Dupa connection details";

QString dsn = QString("DRIVER={SQL SERVER};SERVER=%1;DATABASE=%2;Trusted_Connection=Yes").arg(servername).arg(dbname);

db.setDatabaseName(dsn);

qDebug()<<"Dupa set data base";

if(db.open())
{
    qDebug()<<"open";
}
else
{
     qDebug()<<"Error = "<<db.lastError().text();
}

And it all worked as expected. I could open the database, read from it, perform certain queries, but not after I used a VPN, I can no longer connect to the database.

I have tried to disconnect from the VPN but with no success I still cannot connect.

The error code is:

enter image description here

1

There are 1 best solutions below

1
Denise P. On

One solution that worked for me was to change the driver to SQL Server Native Client 11.0: DRIVER={SQL Server Native Client 11.0};

You can see the name of the drivers in ODBC Data Source Administrator.

check this post: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified