连接Oracle的ADO操作de简单多线程~

类别:VC语言 点击:0 评论:0 推荐:

多线程 (初始化连接数据库 有自己的Splash 显示图片)

// Thread in MySplash Init

       HWND hWnd=this->GetSafeHwnd();

       m_pThread=AfxBeginThread(MyAdoConnect,hWnd,THREAD_PRIORITY_NORMAL);//启动线程THREAD_PRIORITY_HIGHEST

       m_pThread->m_bAutoDelete=FALSE;    //线程为手动删除

// 线程函数

UINT MyAdoConnect(LPVOID pParam)

{

       // COM初始化

       ::CoInitialize(0);

       _ConnectionPtr pConn;

       HRESULT hr;

       hr = pConn.CreateInstance(__uuidof(Connection));

      

       if(SUCCEEDED(hr))

       {

              try

              {

                     pConn->ConnectionString = "Provider=OraOLEDB.Oracle.1;Password=LMS;Persist Security Info=True;User ID=LMS;Data Source=oradb1";//设置连接字符串

                     pConn ->ConnectionTimeout = 10;                //设置连接的超时时间,可选

                     pConn ->CursorLocation    = adUseServer; //设置光标的位置,可选

                     pConn ->Open("","","",-1);

              }

              catch(_com_error& e)

              {

                     CString StrErr;

                     StrErr.Format("出错,连接数据库错误~\n错误:%s",e.ErrorMessage());

                     AfxMessageBox(StrErr);

                     ::PostMessage( (HWND)pParam,WM_CLOSE,0,0);

                     bpConn = false;

                     return FALSE;

              }

       }

       theApp.SetConn(pConn);

       ::PostMessage( (HWND)pParam,WM_CLOSE,0,0);

       bpConn = true;

       return TRUE;

}

本文地址:http://com.8s8s.com/it/it316.htm