日期:2014-05-16  浏览次数:20505 次

Oracle oledb 打包并集成到程序安装包(VC ADO访问Oracle)

      最近有一个项目和oracle交互,我用的是ADO的方式进行试问操作。

      首先把数据库连接的东东记录一下,老了记性不好啊!

      操作如下:

           //连接串这么写的话就可以不用配置 tnsnames.ora配置文件了(网上很多教程都让改这个配置文件)

           strConnect.Format("Provider=OraOLEDB.Oracle.1;Password=%s;Persist Security Info=True;User ID=%s;\
                          Data Source=\"(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = %s)(PORT = %s)) )(CONNECT_DATA = (SID = %s)))\"",
                          strPWD, strUID, strHost, strPort, strSid);


           hr = m_pConnection.CreateInstance(__uuidof(Connection));
           try
           { 
                 m_pConnection->ConnectionTimeout = lConnectTime;
                 hr = m_pConnection->Open((LPCTSTR)strConnect, "", "", adModeUnknown);
                 if(FAILED(hr))
                 {
                       SHAREDATA.g_pMainFrame->Alert(_T("数据库连接失败,请检查数据库!"));
                       return FALSE;
                 }
           }
          catch(_com_error e)
          {  
              CString err;
              err.Format(_T("数据库连接错误!\r\n错误信息:%s:"),e.ErrorMessage());
              SHAREDATA.g_pMainFrame->Alert(err);
               return FALSE;
          } 

          m_bConnectDB = TRUE;

 

 

         //查询数据部分

         if( m_pUserRecSet )
         {
             if( m_pUserRecSet->State )
             m_pUserRecSet->Close();
             m_pUserRecSet = NULL;
         }
         try{
               m_pUserRecSet.CreateInstance(__uuidof(Recordset));
        &