Re: How to get ODBC the status of connection?
- From: Hooyoo <zhaohuyong@xxxxxxxxx>
- Date: Tue, 07 Aug 2007 23:10:17 -0700
On Aug 7, 8:15 pm, Bob Hairgrove <NoSpamPle...@xxxxxxxx> wrote:
On Tue, 07 Aug 2007 00:09:17 -0700, Hooyoo <zhaohuy...@xxxxxxxxx>
wrote:
How can I get the status from the handle of connection? I have
initialized a connection at the beginning, but I need know whether the
connection is still established when I execute a sql statement. Is
there such kind of ODBC API?
For ODBC ver. 3.5, you can call SQLGetConnectAttr() with the argument
SQL_ATTR_CONNECTION_DEAD (see the "ODBC Programmer's Reference" for
details on how to call this function). I'm not aware of how this is
done in earlier ODBC versions; presumably you would just trap the
error which occurs when the SQL statement is prepared or executed.
If the handle itself is invalid, the call to SQLGetConnectAttr
returns SQL_INVALID_HANDLE.
--
Bob Hairgrove
NoSpamPle...@xxxxxxxx
Why does it always return 0 whether the DB server is running or not?
My code looks like:
bool ODBCWrapper::IsConnected()
{
SQLINTEGER isConnected = 0, length = 0;
retcode_ = SQLGetConnectAttr(hdbc_, SQL_ATTR_CONNECTION_DEAD,
&isConnected,
sizeof(SQLINTEGER),&length);
if(retcode_ == SQL_SUCCESS || retcode_ == SQL_SUCCESS_WITH_INFO)
{
return (isConnected != 0); //It always is 0. Why ?????????
}
else
{
return false;
}
}
.
- Follow-Ups:
- Re: How to get ODBC the status of connection?
- From: Bob Hairgrove
- Re: How to get ODBC the status of connection?
- References:
- How to get ODBC the status of connection?
- From: Hooyoo
- Re: How to get ODBC the status of connection?
- From: Bob Hairgrove
- How to get ODBC the status of connection?
- Prev by Date: Re: How to get ODBC the status of connection?
- Next by Date: bcp_init throw exception
- Previous by thread: Re: How to get ODBC the status of connection?
- Next by thread: Re: How to get ODBC the status of connection?
- Index(es):
Relevant Pages
|