VC++6.0通过ado远程连接Oracle

1、新建一个基于对话框的工程zjy,在stdafx.h中所有的#include后加:

#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename ("EOF","adoEOF")

2、在zjydlg.h中声明 :

_ConnectionPtr m_pConnection;
 _RecordsetPtr m_pRecordset;

3、

      m_pConnection.CreateInstance(__uuidof(Connection));
         m_pRecordset.CreateInstance(__uuidof(Recordset));
         try
   {

 //没有配置oracle客户端情况下ado连接字符串
    CString  m_sConn="Provider=OraOLEDB.Oracle.1;Password=platform1234;Persist Security Info=True;User ID=platform;Data Source=\"(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 服务器地址)(PORT = 1521)) )(CONNECT_DATA = (SID = 数据库实例名)))\"";

 //配置好了oracle客户端 情况下ado连接字符串
 // CString   m_sConn="Provider=OraOLEDB.Oracle.1;Password=pwd;Persist Security Info=True;User ID=userid;server=serveraddress;Data Source=本地服务名";
    m_pConnection->Open((_bstr_t)m_sConn,"","",adConnectUnspecified);
 
 //下面是查询数据的例子
       CString strSql="select * from admin";
    BSTR bstrSQL = strSql.AllocSysString();
    m_pRecordset->Open(bstrSQL,(IDispatch*)  m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText); 
                     
     _variant_t TheValue; //VARIANT数据类型
    while(!m_pRecordset->adoEOF)
    {
      i=i+1;
      TheValue= m_pRecordset->GetCollect("name");//得到字段BIG_NAME的值
      if(TheValue.vt!=VT_NULL)
       m_edit+=(char*)_bstr_t(TheValue);
      UpdateData (false);
      m_pRecordset->MoveNext();
    }
     m_pRecordset->Close();
      m_pConnection->Close();
   }
  catch (_com_error e)//异常处理
  {
   AfxMessageBox(e.Description());
   long errorCode=e.WCode();
   if(3127==errorCode) AfxMessageBox("表不存在");
   if(3092==errorCode) AfxMessageBox("表已经存在");
    return ;
  }

红色部分为ado的连接字符串。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值