您的位置:首页 > 数据库 > Oracle

VC使用ADO连接远程oracle数据库

2014-05-23 14:55 148 查看
_ConnectionPtr pConn;//连接对像

_RecordsetPtr pRect;//记录集对象

_CommandPtr pCmd;//命令对象

pRect.CreateInstance(__uuidof(Recordset));

pConn.CreateInstance(__uuidof(Connection));//L连接对像

pCmd.CreateInstance(__uuidof(Command));//命令对象

_bstr_t strConn = "Provider=OraOLEDB.Oracle.1;User ID=%s;Password=%s;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=%s)(PORT=%s))(CONNECT_DATA=(SERVICE_NAME = %s)));Persist Security Info=False"; //这个是远程

//strConn = "Provider=OraOLEDB.Oracle.1;Persist Security Info=True;DATABASE=%s;User ID=%s;Password= %s;"; //这个是本地

HRESULT rValue = pConn->Open(strConn,"","",adModeUnknown);

if (rValue == S_FALSE) { return; }

CString str = "select * from cc_bank";

pRect = pConn->Execute(_bstr_t(str),NULL,adCmdText);

pRect->MoveFirst();

while (pRect->adoEOF==VARIANT_FALSE)

{

  CString str = LPSTR(_bstr_t(pRect->GetCollect("cnname")));

  MessageBox(str);

  pRect->MoveNext();

}

  pRect->Close();

  pConn->Close();

  pRect.Release();

  pConn.Release();

  pCmd.Release();

}

catch(_com_error &e)

{

  MessageBox(e.ErrorMessage());

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: