zoukankan      html  css  js  c++  java
  • 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=(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());  

    }

  • 相关阅读:
    LeetCode #1021. Remove Outermost Parentheses 删除最外层的括号
    使用Maven运行测试提示Module sdk 1.5的解决方法
    Map.Entry使用详解
    c++基础(一)
    Python_正则表达式
    使用PIL生成验证码
    OpenCV_图像平滑
    OpenCV—图像阈值
    OpenCV形状变换
    使用OpenCV读写图片
  • 原文地址:https://www.cnblogs.com/dengpeng1004/p/3747736.html
Copyright © 2011-2022 走看看