示例#1
0
bool COleDBConnectionProp::ConnectMSOracle(ATL::CDataSource* pDataSource,CSession* pSession)
{
	ASSERT(pDataSource);

	m_strDatabaseName = g_sDBName;
	m_strLoginName = g_sDBUser;
	m_strPassword = g_sDBPassword;
	m_strServerName = g_sDBDNS;


	CComBSTR bstrServer(m_strServerName);
	CComBSTR bstrUser(m_strLoginName);
	CComBSTR bstrPassword(m_strPassword);
	CComBSTR bstrDatabase(m_strDatabaseName);


	if (pSession && pSession->m_spOpenRowset != NULL)
		pSession->m_spOpenRowset.Release();

	
	CDBPropSet	dbinit(DBPROPSET_DBINIT);

	dbinit.AddProperty(DBPROP_AUTH_PASSWORD, bstrPassword);
	dbinit.AddProperty(DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, false);
	dbinit.AddProperty(DBPROP_AUTH_USERID, bstrUser);
	dbinit.AddProperty(DBPROP_INIT_DATASOURCE, bstrDatabase);
	dbinit.AddProperty(DBPROP_INIT_LCID, (long)1049);
	dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4);

		
	
	if(FAILED(pDataSource->Open(_T("MSDAORA"), &dbinit)))
	{
		CString strMsg = "Cannot connect to data source";
		strMsg += "\nDatabase\t= "	+ m_strDatabaseName;
		strMsg += "\nLogin\t= "		+ m_strLoginName;
		strMsg += "\nPassword\t= "	+ m_strPassword;

		AfxMessageBox(strMsg);
		if(pDataSource)
		{
			pDataSource->Close();
		}
		goto ErrorExit;
	}
	else
	{
		if (pSession && pSession->Open(*pDataSource) != S_OK)
		{
			AfxMessageBox(_T("Couldn't create session on data source"));
			goto ErrorExit;
		}
	}
	return true;

ErrorExit:
	CloseConnection();
	return false;
}
HRESULT CTCPropBagOnRegKey::_CreateRemoteObject(const _bstr_t& strServer,
  const _bstr_t& strName, IUnknown** ppunkObj, IErrorLog* pErrorLog)
{
  // If DCOM is not installed, take appropriate action
  MCOle32_dll& libOle32 = GetOle32Lib();
  if (!libOle32.Exists_CoCreateInstanceEx())
    return !strServer.length() ?
      CreateLocalObject(strName, ppunkObj, pErrorLog) : E_UNEXPECTED;

  // Read the CLSID of the object saved on the specified subkey
  CLSID clsid;
  CRegKey subkey;
  _bstr_t strObjectID;
  HRESULT hr = GetObjectCLSID(strName, clsid, subkey, strObjectID,
    pErrorLog);
  if (FAILED(hr))
    return hr;

  // Create the object
  USES_CONVERSION;
  _bstr_t bstrServer(strServer);
  COSERVERINFO csi = {0, bstrServer, NULL, 0};
  MULTI_QI mqi = {&IID_IPersistPropertyBag, NULL, 0};
  DWORD dwCtx = CLSCTX_ALL | CLSCTX_REMOTE_SERVER;
  hr = libOle32.CoCreateInstanceEx(clsid, NULL, dwCtx, &csi, 1, &mqi);
  if (FAILED(hr))
  {
    // Use local resources
    MCLibRes res;

    // Format a description string
    _bstr_t strDesc;
    strDesc.Format(IDS_FMT_FAIL_CREATE_CLSID, strObjectID);

    // Log the error
    USES_CONVERSION;
    return LogError("CreateObject", strDesc, hr, T2COLE(strName), pErrorLog);
  }

  // Attach the interface pointer to the smart pointer
  IPersistPropertyBagPtr pppb((IPersistPropertyBag*)mqi.pItf, false);
  
  // Load the object's persistent properties
  CComObjectStack<CTCPropBagOnRegKey> bag;
  bag.Init(subkey, strName, this);
  hr = pppb->Load(&bag, pErrorLog);
  if (FAILED(hr))
    return hr;

  // Detach the IUnknown* and copy to the [out] parameter, don't Release it
  *ppunkObj = pppb.Detach();

  // Indicate success
  return S_OK;
}
示例#3
0
bool COleDBConnectionProp::ConnectMSAccess(ATL::CDataSource* pDataSource,CSession* pSession)
{
	ASSERT(pDataSource);

	m_strDatabaseName = g_sDBName;
	m_strLoginName = g_sDBUser;
	m_strPassword = g_sDBPassword;
	m_strServerName = g_sDBDNS;

	CComBSTR bstrServer(m_strServerName);
	CComBSTR bstrUser(m_strLoginName);
	CComBSTR bstrPassword(m_strPassword);
	CComBSTR bstrDatabase(m_strDatabaseName);


	if (pSession && pSession->m_spOpenRowset != NULL)
		pSession->m_spOpenRowset.Release();

	
	
	CLSID clsid = {0xdee35070L,0x506b,0x11cf, 
	              {0xb1,0xaa,0x0,0xaa,0x0,0xb8,0xde,0x95}};

	
	if(FAILED(pDataSource->Open(clsid, m_strDatabaseName, NULL, NULL, DB_MODE_SHARE_EXCLUSIVE)))
	{
		CString strMsg = "Cannot connect to data source";
		strMsg += "\nDatabase\t= "	+ m_strDatabaseName;

		AfxMessageBox(strMsg);
		if(pDataSource)
		{
			pDataSource->Close();
		}
		goto ErrorExit;
	}
	else
	{
		if (pSession && pSession->Open(*pDataSource) != S_OK)
		{
			AfxMessageBox(_T("Couldn't create session on data source"));
			goto ErrorExit;
		}
	}
	return true;

ErrorExit:
	CloseConnection();
	return false;
}
示例#4
0
bool COleDBConnectionProp::ConnectDB2(ATL::CDataSource* pDataSource,CSession* pSession)
{
	ASSERT(pDataSource);

	m_strDatabaseName = g_sDBName;
	m_strLoginName = g_sDBUser;
	m_strPassword = g_sDBPassword;
	m_strServerName = g_sDBDNS;


	CComBSTR bstrServer(m_strServerName);
	CComBSTR bstrUser(m_strLoginName);
	CComBSTR bstrPassword(m_strPassword);
	CComBSTR bstrDatabase(m_strDatabaseName);


	if (pSession && pSession->m_spOpenRowset != NULL)
		pSession->m_spOpenRowset.Release();

	
		
	if(FAILED(pDataSource->Open(_T("IBMDADB2.1"), m_strDatabaseName, m_strLoginName, m_strPassword )))
	{
		CString strMsg = "Cannot connect to data source";
		strMsg += "\nDatabase\t= "	+ m_strDatabaseName;
		strMsg += "\nLogin\t= "		+ m_strLoginName;
		strMsg += "\nPassword\t= "	+ m_strPassword;

		AfxMessageBox(strMsg);
		if(pDataSource)
		{
			pDataSource->Close();
		}
		goto ErrorExit;
	}
	else
	{
		if (pSession && pSession->Open(*pDataSource) != S_OK)
		{
			AfxMessageBox(_T("Couldn't create session on data source"));
			goto ErrorExit;
		}
	}
	return true;

ErrorExit:
	CloseConnection();
	return false;
}