Connect SqlServer open funcation nerver return



  • 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 ?



  • 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 ?



  • 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]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.