数据库连接超时的设置

yanjing_mail 2009-03-09 11:25:01
我在数据库连接里面加了10s连接超时,为什么不管用呢?例如下面的ip地址改成192.168.1.22要等待30多秒才会返回false。

BOOL CAdoDB::Open(LPCTSTR lpszConnect, long lOptions)
{
m_pConn.CreateInstance("ADODB.Connection");
//初始化Recordset指针
m_pRs.CreateInstance(_uuidof(Recordset));
m_strConn = lpszConnect;
if (m_strConn.IsEmpty())
{
return FALSE;
}
if (IsOpen()) Close();

try
{
m_pConn->ConnectionTimeout = 10;
m_pConn->Open(_bstr_t("Provider=SQLOLEDB;Server=192.168.1.21;Database=hkcdb;User ID=sa;pwd=sasasa"), "", "", adConnectUnspecified);
}
catch (_com_error e)//异常处理
{
return FALSE;
//AfxMessageBox(e.ErrorMessage());
}
//如果打开状态则连接状态为TRUE
if(m_pConn->State == adStateOpen)
{
return TRUE;
}
return FALSE;
}
...全文
159 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
晨钟暮鼓 2009-03-10
  • 打赏
  • 举报
回复
學習一下,聽廳各位的高見
闪破风浪 2009-03-10
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 oyljerry 的回复:]
需要数据库等支持...
[/Quote]
Yes~
oyljerry 2009-03-10
  • 打赏
  • 举报
回复
需要数据库等支持...
shakaqrj 2009-03-10
  • 打赏
  • 举报
回复
Use the ConnectionTimeout property on a Connection object if delays from network traffic or heavy server use make it necessary to abandon a connection attempt. If the time from the ConnectionTimeout property setting elapses prior to the opening of the connection, an error occurs and ADO cancels the attempt. If you set the property to zero, ADO will wait indefinitely until the connection is opened. Make sure the provider to which you are writing code supports the ConnectionTimeout functionality.

stavck 2009-03-09
  • 打赏
  • 举报
回复
你的代码是正确的。
为什么没有起左右,可能和操作系统有关。
也可能和数据库有关。
fandh 2009-03-09
  • 打赏
  • 举报
回复
http://topic.csdn.net/t/20051202/19/4434621.html
这里面有说明!

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧