QSqldatabase open() failed to connect SQL server on other than default 1433 port
SQL server uses other than default 1433 port (e.g. 5555), system DSN created using the port 5555 and tested completed successfully.
However, QSqlDatabase failed to open database.
The code snippets:
Code:
db->setDatabaseName("test");
db->setUserName(userName);
db->setPassword(passWord);
if ( db->open() ){
///Database open successfully.....
}
else
{
///Database open failed
}
It's greatly appreciated for any help to solve this problem.
Re: QSqldatabase open() failed to connect SQL server on other than default 1433 port
Re: QSqldatabase open() failed to connect SQL server on other than default 1433 port
Thank you for your reply. The lastError().test() prints out as follow.
"[Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). QODBC3: Unable to connect"
Is any possible it still uses default 1433 port instead of specified port 5555?
Re: QSqldatabase open() failed to connect SQL server on other than default 1433 port
Check that with QSqlDatabase::port(). Because in your example code you do not set the port.
Re: QSqldatabase open() failed to connect SQL server on other than default 1433 port
QSqlDatabase.port() return -1.