how to set the connect blocking time when use QSqlDatabase::open()?
-
now i use QSqlDatabase::open() to connect the sql sever.
After reading Qt help,i use QSqlDatabase::setConnectOptions() to set the blocking time.QSqlDatabase db; /*......*/ db.setConnectOptions("SQL_ATTR_LOGIN_TIMEOUT=3");
when i input the wrong ip,like196.168.0.999,the code work,db.open() will blocking 3s .
but when i input a legal but unconnectable ip like 196.168.0.1, the code doesn‘t work,db.open() will blocking about 50s .How to solve this problem?how to set the blocking time?
-
now i use QSqlDatabase::open() to connect the sql sever.
After reading Qt help,i use QSqlDatabase::setConnectOptions() to set the blocking time.QSqlDatabase db; /*......*/ db.setConnectOptions("SQL_ATTR_LOGIN_TIMEOUT=3");
when i input the wrong ip,like196.168.0.999,the code work,db.open() will blocking 3s .
but when i input a legal but unconnectable ip like 196.168.0.1, the code doesn‘t work,db.open() will blocking about 50s .How to solve this problem?how to set the blocking time?
@boom-stack
Do you mean it only blocks 50s when you have that line, or would it still block 50s without that line?You don't say anything about what your database is. In any case, that option will be passed on directly from Qt, Qt does nothing about it, so you should search the web for solutions relevant to your database.
-
i use QSqlDatabase to connect the sql server.
With that line or without that line,when i input a legal but unconnectable ip like 196.168.0.1,they both will block 50s. -
i use QSqlDatabase to connect the sql server.
With that line or without that line,when i input a legal but unconnectable ip like 196.168.0.1,they both will block 50s.@boom-stack said in how to set the connect blocking time when use QSqlDatabase::open()?:
i use QSqlDatabase to connect the sql server.
I know that. But that says nothing about what the SQL server is. It might be SQLite, MySQL, MariaDB, PostgreSQL, ... Whichever it is, that is who interprets the
SQL_ATTR_LOGIN_TIMEOUT=3
--- I think it's actually the ODBC driver, so that may be what you have to Google to address your question. -
yeah it's actually the ODBC driver,but i just don’t know how to set the connect blocking time by use QSqlDatabase::setConnectOptions().
except this linedb.setConnectOptions("SQL_ATTR_LOGIN_TIMEOUT=3");
what should i set?

-
yeah it's actually the ODBC driver,but i just don’t know how to set the connect blocking time by use QSqlDatabase::setConnectOptions().
except this linedb.setConnectOptions("SQL_ATTR_LOGIN_TIMEOUT=3");
what should i set?

@boom-stack
I don't know either, that's why I said you'll want to Google!Purely at a guess, since you're saying it spends 50 seconds trying and failing to connect, did you investigate
SQL_ATTR_CONNECTION_TIMEOUT
? -
yes i try,but it doesn't work
hhhhokok,whatever thank you bro. -
yes i try,but it doesn't work
hhhhokok,whatever thank you bro.@boom-stack
Then I think you have a problem! I see e.g. https://stackoverflow.com/questions/2309684/connection-timeout-in-odbc saying you should do this viaSQL_ATTR_CONNECTION_TIMEOUT
, but then as per the last answer there https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2012/ms131709(v%3Dsql.110) statesThe SQL Server Native Client ODBC driver ignores the setting of SQL_ATTR_CONNECTION_TIMEOUT.
So it may depend on on which client ODBC driver you use.....
I would do a lot of Googling :)
-
i did a lot google,but maybe i ignore something.
thank you bro!it help