[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.4

Connection Pooling Using CDatabase

Asked by Kasinadh in Windows MFC Programming

Tags: cdatabase, connection, pooling

I was trying to setup Connection Pooling on an existing MFC based application.
The backend is Oracle and I used CRecordset to get access to the data.

I followed an article on the Codeguru website..  http://www.codeguru.com/Cpp/data/mfc_database/odbc/article.php/c1149/

I followed the steps written in it ( listed below), but, I have questions about how to accomplish 3 of them....
done. 1. Create (or download) the CDatabase-derived class, and add it to your Project
done. 2. Create a member of the CDatabase-derived class in your CWinApp-derived (Application) class
done. 3. Create a SQLHANDLE data member in your Application class for the Enviroment Handle
??..    4. Add an accessor function that returns the address of the CDatabase-derived member you added in the previous step
??..    5. Make the necessary SQLSetEnvAttr(...) and SQLAllocHandle(...) calls as specified above
done. 6. Initially open your CDatabase-derived object (if you are using SQL Authentication)
??      7. Whenever you instantiate a CRecordset-derived object, pass the address of the CDatabase-derived class into its constructor

First of all,
1) If this is one of the better ways to accomplish Connection pooling, please advise on how to complete this based on code snippets below.
2)If there's another way of doing this (I have 20 tables), please step through. I cant say I'm good at this and any help is greatly appreciated.



Here's my code in snippets from different files.

----------- CCPDatabase class.. as is from article.Wrapper class across CDatabase

class      CCPDatabase : public CDatabase
{
public:
      /**/                  CCPDatabase()
      {
      };
      //
      //      Code Is Copied From CDatabase Source Code...
      //
      virtual      BOOL      OpenEx( LPCTSTR lpszConnectString, DWORD dwOptions = 0 )
      {
            dwOptions |= noOdbcDialog;                                          // Force NoDialog
                              .....
                             .....
}

}
--------------------------------------------------------------------

-----------------MyWinApp Class

::InitInstance
{
      // Setup the Connection Pool
      //   m_shSQLEnv Is A SQLHANDLE Member That Must Be Freed When Your
      //   Application Terminated
      //
            SQLRETURN srRetCode = 0;
            srRetCode = SQLSetEnvAttr( NULL, SQL_ATTR_CONNECTION_POOLING,
                        (SQLPOINTER)SQL_CP_ONE_PER_DRIVER, 0 );                  // Enable Connection Pooling
            srRetCode = SQLAllocHandle( SQL_HANDLE_ENV, NULL, &m_shSQLEnv ); // Get Global Handle
      // End setup of Connection Pool


      // ****************************************************************
      // Calling the CDatabase Open function for the first and ONLY time
      // ****************************************************************
   if( !m_shPDB.IsOpen( ) &&
       !m_shPDB.OpenEx( NULL ) )
      return FALSE;
      // **********return false on fail***********************************

}
-------------------------------------------------------------------------------------------------------------------
---------------------------- One of my CRecordsets.CPP file
// DetailSet.cpp : implementation file
//

#include "stdafx.h"
#include "MyWinApp.h"
#include "DetailSet.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDetailSet

IMPLEMENT_DYNAMIC(CDetailSet, CRecordset)

CDetailSet::CDetailSet(CCPDatabase* pDatabase)
      : CRecordset(pDatabase)
{
      //{{AFX_FIELD_INIT(CDetailSet)
      m_Item = _T("");
      m_Seq = 0;
      m_Description = _T("");
      m_FeatureCode = _T("");
      m_RecordType = _T("");
      m_ORDERNO = _T("");
      m_nFields = 6;
      //}}AFX_FIELD_INIT
      m_nDefaultType = dynaset;

}


CString CDetailSet::GetDefaultConnect()
{
      return _T("ODBC;DSN=OraTest;UID=user10;PWD=password1");
}

CString CDetailSet::GetDefaultSQL()
{
      return _T("[SC_FRAMES].[SC_FRMSCH_DETAIL]");
}

void CDetailSet::DoFieldExchange(CFieldExchange* pFX)
{
  ......
}

/////////////////////////////////////////////////////////////////////////////
// CDetailSet diagnostics

#ifdef _DEBUG
void CDetailSet::AssertValid() const
{
      CRecordset::AssertValid();
}

void CDetailSet::Dump(CDumpContext& dc) const
{
      CRecordset::Dump(dc);
}
#endif //_DEBUG
-------------------------------------------------------------------------------------------------------
------------------------------Recordset.h
#if !defined(AFX_DETAILSET_H__AD149183_516C_11D2_8176_0060979C789B__INCLUDED_)
#define AFX_DETAILSET_H__AD149183_516C_11D2_8176_0060979C789B__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// DetailSet.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CDetailSet recordset

class CDetailSet : public CRecordset
{
public:
      CDetailSet(CCPDatabase* pDatabase = &((CFrameSchedApp *)AfxGetApp())->m_shPDB);
      DECLARE_DYNAMIC(CDetailSet)

// Field/Param Data
      //{{AFX_FIELD(CDetailSet, CRecordset)
      ...........
      //}}AFX_FIELD


// Overrides
      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(CDetailSet)
      public:
      virtual CString GetDefaultConnect();    // Default connection string
      virtual CString GetDefaultSQL();    // Default SQL for Recordset
      virtual void DoFieldExchange(CFieldExchange* pFX);  // RFX support
      //}}AFX_VIRTUAL

// Implementation
#ifdef _DEBUG
      virtual void AssertValid() const;
      virtual void Dump(CDumpContext& dc) const;
#endif
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DETAILSET_H__AD149183_516C_11D2_8176_0060979C789B__INCLUDED_)
----------------------------------------------------------------------------------------------------------------------------
[+][-]04/13/04 12:49 PM, ID: 10816805Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/13/04 02:55 PM, ID: 10817993Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/13/04 03:50 PM, ID: 10818506Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/14/04 10:41 AM, ID: 10825814Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/14/04 10:50 AM, ID: 10825944Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Windows MFC Programming
Tags: cdatabase, connection, pooling
Sign Up Now!
Solution Provided By: bkfirebird
Participating Experts: 1
Solution Grade: A
 
[+][-]04/16/04 05:47 PM, ID: 10847215Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/20/04 09:29 AM, ID: 11118869Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]05/25/04 01:53 PM, ID: 11156015Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89