Hello Gu Lei, > -----Original Message----- > From: Gu Lei [mailto:[EMAIL PROTECTED] > Sent: Dienstag, 6. September 2005 09:45 > To: maxdb list > Subject: Does MaxDB ODBC support SQL_ATTR_CONNECTION_DEAD? > > Hello: > > This is my source code: > bool DBConnection::isDead() > { > SQLINTEGER stringLengthPtr; > SQLINTEGER attr; > SQLRETURN > rc=SQLGetConnectAttr(hdbc,SQL_ATTR_CONNECTION_DEAD,&attr,sizeo > f(attr),&stringLengthPtr); > if(rc<0) > { > cerr<<"Source File : "<<__FILE__<<endl; > cerr<<"Line Number : "<<__LINE__<<endl; > cerr<<"SQLGetConnectAttr failed"<<endl; > cerr<<getSQLError(SQL_HANDLE_DBC,hdbc); > return true; > } > else if(attr == SQL_CD_TRUE) return true; > else return false; > } > > attr always is 0 even when database is stopped. > I need an ODBC function to detect status of database connection. > Is there anything wrong in my code?
SQL_ATTR_CONNECTION_DEAD does not access the data base in order to check the state of the connection. It returns only the state detected by the driver in an earlier made communication step with the kernel. However, it seems that even this is not handled properly in all cases. An easy work around is to try an "select * from dual". If this fails, the connection is broken: : rc = SQLAllocHandle (...stmt...); rc = SQLExecDirect (stmt, "select * from dual", SQL_NTS); SQLFreeHandle (...stmt...); return rc == SQL_SUCCESS; Thanks for reporting Thomas ---------------------------------------------- Dr. Thomas Kötter SAP AG, Berlin NW DT MaxDB MaxDB: all you need! www.mysql.com/products/maxdb www.sapdb.org -- MaxDB Discussion Mailing List For list archives: http://lists.mysql.com/maxdb To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]