当前位置: 首页>>代码示例>>C++>>正文


C++ _ConnectionPtr类代码示例

本文整理汇总了C++中_ConnectionPtr的典型用法代码示例。如果您正苦于以下问题:C++ _ConnectionPtr类的具体用法?C++ _ConnectionPtr怎么用?C++ _ConnectionPtr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了_ConnectionPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: OpenDB

DWORD CNHSQLServerDBO::OpenDB(_ConnectionPtr &pConnection,
                              const wchar_t *const pwchDataSource,
                              const wchar_t *const pwchInitialCatalog,
                              const wchar_t *const pwchUserID,
                              const wchar_t *const pwchPassword)
{
    assert(NULL != pwchDataSource);
    assert(NULL != pwchInitialCatalog);
    assert(NULL != pwchUserID);
    assert(NULL != pwchPassword);

    DWORD dwReturn(0x00);

    wchar_t wchSql[MAX_PATH];
    ZeroMemory(wchSql, sizeof(wchSql));

    // 加载COM组件
    CoInitialize(NULL);
    try
    {
        _snwprintf_s(wchSql, _countof(wchSql), _TRUNCATE, L"Provider=SQLOLEDB; Data Source=%s; Initial Catalog=%s; User ID=%s; Password=%s;",
                     pwchDataSource,
                     pwchInitialCatalog,
                     pwchUserID,
                     pwchPassword);

        pConnection.CreateInstance(L"ADODB.Connection");
        //pConnection->ConnectionTimeout = 5;
        //pConnection->CommandTimeout = 5;
        pConnection->Open((_bstr_t)wchSql, L"", L"", adModeUnknown);
    }
    catch (_com_error &e)
    {
//#ifdef _DEBUG
        const int nErrMsgLength(MAX_PATH);
        wchar_t *pwchErrMsg = new wchar_t[nErrMsgLength]();
        _snwprintf_s(pwchErrMsg, nErrMsgLength, _TRUNCATE, L"CNHSQLServerDBO::OpenDB发生错误(执行%s)。", wchSql);
        // 输出错误信息到输出窗口
        OutputDebugStringW(L"\t");
        OutputDebugStringW(pwchErrMsg);
        OutputDebugStringW(L"\n");
        // 输出错误信息到日志文件
        if (0 != wcscmp(m_wchLogFilePath, L""))
        {
            // 当日志文件路径不为空时,写日志
            CNHLogAPI::WriteLogEx(m_wchLogFilePath, LOG_ERR, L"NHSQLServerDBO", pwchErrMsg);
        }
        if (NULL != pwchErrMsg)
        {
            delete[] pwchErrMsg;
            pwchErrMsg = NULL;
        }
        OutputDBErrMsg(e);
//#endif
        dwReturn = 0x01;
    }

    return dwReturn;
}
开发者ID:musclecui,项目名称:Solution1,代码行数:59,代码来源:NHSQLServerDBO.cpp

示例2: ADOConExec

int CCommDBOper::ADOConExec(_ConnectionPtr &pCon,const CString strCmdSql,CString strDcrCmd,int iWarn)
{	
	//函数功能说明: 由pCon(Connection)对象执行指定SQL命令
	//pCon 数据库连接对象
	//strCmdSql  要执行SQL的命令语句
	//strDcrCmd是对要使用SQL命令的描述
	if (ADOConIsOpened(pCon,iWarn) != RET_OK)   //判断当前连接对象是否已打开
	{
		WarnMessage("指定数据库对象未连接,退出!",iWarn);
		return RET_FAILED;
	}
	try
	{
		pCon->Execute(_bstr_t(strCmdSql),NULL,adCmdText);
	}
	catch (_com_error &e)
	{
		CString strMsg;
		strMsg.Format("%s:%d %s", __FILE__, __LINE__, (LPSTR)e.Description());
		AfxMessageBox(strMsg);
		CString errormessage;
		errormessage.Format("功能说明: %s\r\n数据库连接对象执行下列SQL命令\r\n%s\r\n失败!  错误信息:%s",strDcrCmd,strCmdSql,e.ErrorMessage());
		WarnMessage(errormessage,iWarn);///显示错误信息
		return RET_FAILED;
	}
	return RET_OK;
}
开发者ID:uesoft,项目名称:AutoPHS,代码行数:27,代码来源:CommDBOper.cpp

示例3: GetADOError

///////////////////////////////////////////////////////
//
//	Name: GetADOError
//	Params: Conn1 - connection pointer
//	Returns: ADO error string
//	Description: determines ADO error(s) that occurred 
///////////////////////////////////////////////////////
std::string GetADOError(_ConnectionPtr Conn1)
{
	USES_CONVERSION;
   ErrorsPtr   Errs1 = NULL;
    ErrorPtr    Err1  = NULL;

	std::string sRet("ADO Error. Description: ");
    long        nCount;

   try
    {
	    if( Conn1 == NULL ) return sRet + (std::string)"NULL Connection";
  
		// Enumerate Errors Collection and display properties of each object.
        Errs1  = Conn1->GetErrors();
        nCount = Errs1->GetCount();

        // Loop through Errors Collection
        for( long i = 0; i < nCount; i++ )
        {
            // Get Error Item
            Err1 = Errs1->GetItem((_variant_t)((long)i) );
			sRet += (std::string)" Description: " + (std::string)OLE2T(Err1->GetDescription());
		}
	
		if( Errs1 != NULL )  Errs1->Release(); 
		if( Err1  != NULL )  Err1->Release();  
   }
   catch(...)
   {
	   sRet += " Unknown Error";
   }
	
   return sRet;
}
开发者ID:cice,项目名称:ODBCSocketServer,代码行数:42,代码来源:main-server.cpp

示例4: CloseDB

DWORD CNHSQLServerDBO::CloseDB(_ConnectionPtr &pConnection)
{
    //assert(NULL != pConnection);

    DWORD dwReturn(0x00);

    try
    {
        //关闭连接
        if (NULL!=pConnection && adStateClosed!=pConnection->State)
        {
            pConnection->Close();
        }
        if (NULL != pConnection)
        {
            pConnection.Release();
            pConnection = NULL;
        }
    }
    catch (_com_error &e)
    {
//#ifdef _DEBUG
        // 输出错误信息到输出窗口
        OutputDebugStringW(L"\t");
        OutputDebugStringW(L"CNHSQLServerDBO::CloseDB发生错误。");
        OutputDebugStringW(L"\n");
        // 输出错误信息到日志文件
        if (0 != wcscmp(m_wchLogFilePath, L""))
        {
            // 当日志文件路径不为空时,写日志
            CNHLogAPI::WriteLogEx(m_wchLogFilePath, LOG_ERR, L"NHSQLServerDBO", L"CNHSQLServerDBO::CloseDB发生错误。");
        }
        OutputDBErrMsg(e);
//#endif
        dwReturn = 0x01;
    }

    // 卸载COM组件
    CoUninitialize();

    return dwReturn;
}
开发者ID:musclecui,项目名称:Solution1,代码行数:42,代码来源:NHSQLServerDBO.cpp

示例5: ADOCloseConnectDB

//断开指定数据库连接对象连接
int CCommDBOper::ADOCloseConnectDB(_ConnectionPtr &pCon,int iWarn)
{
	if ((pCon != NULL) && (pCon->State == adStateOpen) )
	{
		try
		{
			pCon->Close();
		}
		catch (_com_error &e)
		{
			CString strMsg;
			strMsg.Format("%s:%d %s", __FILE__, __LINE__, (LPSTR)e.Description());
			AfxMessageBox(strMsg);
		}
	}
	return RET_OK;
}
开发者ID:uesoft,项目名称:AutoPHS,代码行数:18,代码来源:CommDBOper.cpp

示例6: ExecuteDML

DWORD CNHSQLServerDBO::ExecuteDML(const _ConnectionPtr &pConnection, const wchar_t *const pwchSQL, int *const pnRowsInvolved/*=NULL*/)
{
    assert(NULL != pConnection);
    assert(NULL != pwchSQL);

    DWORD dwReturn(0x00);

    try
    {
        _variant_t vRA;
        pConnection->Execute((_bstr_t)pwchSQL, &vRA, adCmdText);
        if (NULL != pnRowsInvolved)
        {
            *pnRowsInvolved = static_cast<int>(vRA);
        }
    }
    catch (_com_error &e)
    {
//#ifdef _DEBUG
        const int nErrMsgLength(MAX_PATH);
        wchar_t *pwchErrMsg = new wchar_t[nErrMsgLength]();
        _snwprintf_s(pwchErrMsg, nErrMsgLength, _TRUNCATE, L"CNHSQLServerDBO::ExecuteDML发生错误(执行%s)。", pwchSQL);
        // 输出错误信息到输出窗口
        OutputDebugStringW(L"\t");
        OutputDebugStringW(pwchErrMsg);
        OutputDebugStringW(L"\n");
        // 输出错误信息到日志文件
        if (0 != wcscmp(m_wchLogFilePath, L""))
        {
            // 当日志文件路径不为空时,写日志
            CNHLogAPI::WriteLogEx(m_wchLogFilePath, LOG_ERR, L"NHSQLServerDBO", pwchErrMsg);
        }
        if (NULL != pwchErrMsg)
        {
            delete[] pwchErrMsg;
            pwchErrMsg = NULL;
        }
        OutputDBErrMsg(e);
//#endif
        dwReturn = 0x01;
    }

    return dwReturn;
}
开发者ID:musclecui,项目名称:Solution1,代码行数:44,代码来源:NHSQLServerDBO.cpp

示例7: tableExists

BOOL newproject::tableExists(_ConnectionPtr pCon, CString tbn)
{
    if(pCon==NULL || tbn=="")
        return false;
    _RecordsetPtr rs;
    if(tbn.Left(1)!="[")
        tbn="["+tbn;
    if(tbn.Right(1)!="]")
        tbn+="]";
    try {
        rs=pCon->Execute(_bstr_t(tbn),NULL,adCmdTable);
        rs->Close();
        return true;
    }
    catch(_com_error e)
    {
        return false;
    }

}
开发者ID:uesoft,项目名称:AutoIPED,代码行数:20,代码来源:newproject.cpp

示例8: SetConnection

bool RxADO::SetConnection(CString LinkString)
{
	::CoInitialize(NULL);
	cnn=NULL;
	cnn.CreateInstance(__uuidof(Connection));
	cnn->ConnectionString=(_bstr_t)LinkString;
	try{
		cnn->Open(L"",L"",L"",adCmdUnspecified);
	}
	catch(_com_error& e)
	{
		ErrorsPtr pErrors=cnn->GetErrors();
		if (pErrors->GetCount()==0)
		{	
			CString ErrMsg=e.ErrorMessage();
			MessageBox(NULL,"·¢Éú´íÎó:\n\n"+ErrMsg,"ϵͳÌáʾ",MB_OK|MB_ICONEXCLAMATION);	
			return false;
		}
		else
		{
			for (int i=0;i<pErrors->GetCount();i++)
			{
				_bstr_t desc=pErrors->GetItem((long)i)->GetDescription();
				MessageBox(NULL,"·¢Éú´íÎó:\n\n"+desc,"ϵͳÌáʾ",MB_OK|MB_ICONEXCLAMATION);
				return false;
			}
		}	
	}
	return true;
}
开发者ID:ice98,项目名称:mycode_bak,代码行数:30,代码来源:RxADO.cpp

示例9: ConnectData

UINT CSplash::ConnectData(LPVOID ps)
{
	AfxOleInit(); //初始化COM库
	if(FAILED(HospitalConnect.CreateInstance(__uuidof(Connection))))
	{
		((CSplash *)ps)->ConnectFlag=true;
		((CSplash *)ps)->timer_count=3; //连接COM失败标志
		((CSplash *)ps)->SendMessage(WM_CLOSE,0,0);
	
		return 0;
	}

	try{
		
		HospitalConnect->Open(_bstr_t(theApp.strConn),"","",adModeUnknown);
		((CSplash *)ps)->ConnectFlag=true;
		((CSplash *)ps)->timer_count=1; //连接成功标志
		((CSplash *)ps)->SendMessage(WM_CLOSE,0,0);
	
		return 1;
	}
	catch(_com_error e)
	{
		((CSplash *)ps)->ConnectFlag=true; //作为进度条线程停止标志
		((CSplash *)ps)->timer_count=2; //连接失败标志

		((CSplash *)ps)->SendMessage(WM_CLOSE,0,0);
	

		return 2;
	
	}


}
开发者ID:lingshaoqing,项目名称:Cplusplus-Source-Code,代码行数:35,代码来源:Splash.cpp

示例10: FieldToOtherField

/*
 µ±nStale=1ʱ ×Ö·û×ֶηµ»Ø×Ö·û×Ö¶Î
 µ±nStale=2ʱ ÊýÖµ×ֶηµ»Ø×Ö·û×Ö¶Î
 µ±nStale=3ʱ ÈÕÆÚ×ֶηµ»Ø×Ö·û×Ö¶Î
*/
CString RxADO::FieldToOtherField(CString cDataBaseName, CString cFieldName, CString cValue, CString cReturnField, int nStale=1)
{
	CString sSQL,sRTValue;
	_RecordsetPtr Fieldrst;
	Fieldrst.CreateInstance(__uuidof(Recordset));
	Fieldrst.CreateInstance(__uuidof(Recordset));
	if(nStale==1)	//×Ö·û×ֶηµ»Ø×Ö·û×Ö¶Î
			sSQL.Format("SELECT * FROM %s WHERE %s='%s'",cDataBaseName,cFieldName,cValue);
	if(nStale==2)//ÊýÖµ×ֶηµ»Ø×Ö·û×Ö¶Î
			sSQL.Format("SELECT * FROM %s WHERE %s=%s",cDataBaseName,cFieldName,cValue);
	if(nStale==3)//ÈÕÆÚ×ֶηµ»Ø×Ö·û×Ö¶Î
			sSQL.Format("SELECT * FROM %s WHERE %s=#%s#",cDataBaseName,cFieldName,cValue);
	try{
		Fieldrst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
	}
	catch(_com_error&e)
	{
		GetADOErrors(e);
		return "";
	}
	if(GetRecordCount(Fieldrst)<=0)
		return "";
	_variant_t vValue=Fieldrst->GetCollect((_bstr_t)cReturnField);
	if(vValue.vt==VT_EMPTY)
		return "";
	sRTValue=(char*)(_bstr_t)vValue;
	sRTValue.TrimRight();
	sRTValue.TrimLeft();
	return sRTValue;
}
开发者ID:ice98,项目名称:mycode_bak,代码行数:35,代码来源:RxADO.cpp

示例11: GetConnectIP

CString GetConnectIP()
{
	CString  bstr = (char*)theConnection->GetConnectionString();
	int nl = bstr.Find("Data Source=") + strlen("Data Source=");
	int nr = bstr.Find(";", nl);
	return bstr.Mid(nl, nr-nl);
}
开发者ID:niepp,项目名称:sperm-x,代码行数:7,代码来源:SpermView.cpp

示例12: ExitConnect

//断开连接
void ExitConnect(void)
{
	if(m_pRecordset!=NULL){
		m_pRecordset->Close();
		m_pConnection->Close();
	}
	::CoUninitialize();  //释放环境
}
开发者ID:mz247,项目名称:C-C-,代码行数:9,代码来源:adoConnectSQL.cpp

示例13: OnInitADOConn

// //封闭ADO类,方便以后使用
void ADOConn::OnInitADOConn(void)
{
::CoInitialize(NULL);
try
{
//创建connection对象
m_pConnection.CreateInstance("ADODB.Connection");
//设置连接字符串
_bstr_t strConnect="uid=;pwd=;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=Grades.mdb;";
//SERVER和UID,PWD的设置根据实际情况来设置"
/*m_pConnection->Open(strConnect,_T("admin"),_T("owenyang"),adModeUnknown);*/
m_pConnection->Open(strConnect,"admin","owenyang",adModeUnknown);
}
catch (_com_error e)
{
//显示错误信息
AfxMessageBox(e.Description());
}
}
开发者ID:owenyang0,项目名称:ADOConn,代码行数:20,代码来源:ADOConn.cpp

示例14: ExitConnect

void ADOConn::ExitConnect(void)
{
//关闭记录集和连接
if (m_pRecordset!=NULL)
{
m_pRecordset->Close();
 
}
m_pConnection->Close();
::CoUninitialize();
}
开发者ID:owenyang0,项目名称:ADOConn,代码行数:11,代码来源:ADOConn.cpp

示例15: Connect

//连接SQL
void Connect()
  {
	  try{
		  ::CoInitialize(NULL);  //初始化COM环境
		  m_pConnection.CreateInstance(__uuidof(Connection));  //创建连接对象
		  //通过DSN数据源对任何支持ODBC的数据库进行连接
		  //m_pConnection->ConnectionString="Provider=SQLOLEDB.1; Persist Security Info=True; User ID=sa; Password=a1!; Initial Catalog=InTouch; Data Source=WIN-P6OLLUM9PDM"; //请将数据库相应ID与Password更改
          //不通过DSN对SQL SERVER数据库进行连接
		  m_pConnection->ConnectionString="driver={SQL Server};Server=127.0.0.1;DATABASE=InTouch;UID=sa;PWD=a1!";
		  //连接服务器和数据库
          HRESULT hr=m_pConnection->Open("", "", "", 0);
		  if(hr!=S_OK)
			    cout<<"Can not connect to the specified database!"<<endl;

	  }
	  catch(_com_error e){

		  cout<<e.Description()<<endl;
	  }
          
}
开发者ID:mz247,项目名称:C-C-,代码行数:22,代码来源:adoConnectSQL.cpp


注:本文中的_ConnectionPtr类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。