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

时间:2014-05-26 08:01:46   收藏:0   阅读:269

_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());  

}

VC使用ADO连接远程oracle数据库,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!