PDA

View Full Version : QSqlDatabase



raphaelf
9th March 2006, 09:03
Hi everybody,

QT:4.1.1
OS:WinXP
DB: SQL Server 7.0
Compiler: MinGW

I have a small program that are able to connect to a SQL Database via ODBC to our Server.
The connection works fine. If i write in my login Dialog a false password or user name i get emmediately a Error Message from the Databse, that ok.
But if i write for "hostname" a host that not exist my program dont respont for 15 seconds, and after that i get the Error Message from the Database.
So, its possible to set max. 2 seconds for my connection?


Best Regards

raphaelf
10th March 2006, 14:11
Hi everybody!
Should i explain again my problem :o
or i have no chance for solve this problem :cool:
Thanks

zlatko
10th March 2006, 14:14
hm...i think you cant set timeout by own :confused:

raphaelf
10th March 2006, 14:18
hmmm :(
so we will have to live with this problem..
:o

jacek
10th March 2006, 14:22
From Qt docs (http://doc.trolltech.com/4.1/qsqldatabase.html#setConnectOptions):
void QSqlDatabase::setConnectOptions ( const QString & options = QString() )
Sets database-specific options. This must be done before the connection is opened or it has no effect (or you can close() the connection, call this function and open() the connection again).
The format of the options string is a semicolon separated list of option names or option=value pairs. The options depend on the database client used
Try setting the SQL_ATTR_CONNECTION_TIMEOUT option.

raphaelf
10th March 2006, 14:33
Hi Jacek!
Maybe i have a hope :p
but how to set 3 seconds for this Option:


db.setConnectOptions("SQL_ATTR_CONNECTION_TIMEOUT");

jacek
10th March 2006, 14:55
but how to set 3 seconds for this Option
Read carefully my previous post (especially that docs excerpt, which says something about option=value pairs).

raphaelf
10th March 2006, 16:55
Hi Jacek!
I tried this:


QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setConnectOptions("SQL_ATTR_CONNECTION_TIMEOUT=60");
db.setHostName(host);
db.setDatabaseName("DRIVER={SQL Server};SERVER="+host+";DATABASE=inventar;UID="+user+";PWD="+pass+"");
db.setUserName(user);
db.setPassword(pass);
if(!db.open())
{
QMessageBox::information(this,"",db.lastError().text());
ui.pass_le->clear();
return false;
}
else
{
.
.

My program try everytime exactly 15 seconds :o
What could i try?

jacek
10th March 2006, 17:42
Then try specifying the SQL_ATTR_LOGIN_TIMEOUT option too.

raphaelf
10th March 2006, 19:28
Hi :)
I could optimize some seconds :p (from 22 s. to 7 s)
I found out that if i set a value between 0 and ..., i get a error after exaclty 7 seconds. Maybe 7 s are the minimum :cool:


db.setConnectOptions("SQL_ATTR_LOGIN_TIMEOUT=5");

also:


db.setConnectOptions("SQL_ATTR_LOGIN_TIMEOUT=5;SQL_ATTR_CONNECTION_TIMEO UT=5");


Thanks to everybody again for the best support :)

Philip_Anselmo
10th May 2006, 15:15
Holas :o
I was reading this thread and well I noticed that that option works only with ODBC.. and in Qt 4.1...
isn't a way to avoid the freeze that produces the intent to connect to a unreachable host?

as I can't use the ones on the documentation from qt 4.1 because I'm using qt 3.1.2 :rolleyes: license..