首页 > 代码库 > VC使用ADO连接远程oracle数据库

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

_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=http://www.mamicode.com/(SERVICE_NAME "; //这个是远程

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

  HRESULT rValue = http://www.mamicode.com/pConn->Open(strConn,"","",adModeUnknown);   

if (rValue =http://www.mamicode.com/= 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());  

}