0

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

Dale K
  • 25,246
  • 15
  • 42
  • 71

1 Answers1

1

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

Denise P.
  • 11
  • 1