Connect SqlServer open funcation nerver return
-
wrote on 13 Aug 2014, 05:16 last edited by
QSqlDatabase's open function will nerver return when i set wrong SqlServer's IP address. how can i make open function return within the specified time?
-
Did you check on QSqlDatabase::setConnectOptions with SQL_ATTR_CONNECTION_TIMEOUT ?
-
wrote on 13 Aug 2014, 08:14 last edited by
Yes, I use setConnectOptions("SQL_ATTR_LOGIN_TIMEOUT=3;SQL_ATTR_CONNECTION_TIMEOUT=60") before open.
It still need about 1 minute to report open failed... -
What I understand is that you are setting the login time out as 3 and conn time out as 60. Your expectation is that it should return in 3 secs. It is trying to login and connect. In your case it is wrong IP itself. So it is not even in to login phase. It is still trying to connect to IP which it is not able to find. It is working according to timeouts. Did you try setting conntimeout to some lesser value like 10 secs etc ?
-
wrote on 16 Aug 2014, 09:18 last edited by
Yes, I try to use this options: setConnectOptions(“SQL_ATTR_LOGIN_TIMEOUT=30;SQL_ATTR_CONNECTION_TIMEOUT=3”), but nothing change. It seems that options doesn't apply!
[quote author="Dheerendra" date="1407987770"]What I understand is that you are setting the login time out as 3 and conn time out as 60. Your expectation is that it should return in 3 secs. It is trying to login and connect. In your case it is wrong IP itself. So it is not even in to login phase. It is still trying to connect to IP which it is not able to find. It is working according to timeouts. Did you try setting conntimeout to some lesser value like 10 secs etc ?[/quote]
2/5