?
Solved

Invalid Pointer Exception

Posted on 2004-11-08
9
Medium Priority
?
510 Views
Last Modified: 2013-11-20
_RecordsetPtr pRecordset;
      _ConnectionPtr pConnection;
      _bstr_t query=CStr2bstr(strSetMainSQL);
      bool connectionEstablished=false;
      try
    {
            CMASSMAILERApp* app=(CMASSMAILERApp*)AfxGetApp();
            CString appPath=app->GetApplicationPath ();
            pConnection.CreateInstance(__uuidof(Connection));
            pConnection->Provider = "Microsoft.Jet.OLEDB.4.0";
            //char *sConn=new char[250];
            CString sConn;
        sConn = appPath+"\\massmailer_database.mdb";
            pConnection->Open ((_bstr_t)sConn,"","",adConnectUnspecified);            
            connectionEstablished=true;
            
      }
      catch(_com_error &e)
      {            
            connectionEstablished=false;
            AfxMessageBox("First Chance of Error");
      }
      if(connectionEstablished)
      {
            try
            {
                  _bstr_t b_databaseText;
                  CString m_consu_Id,m_name,m_mailid;
                  CString strid;      
                  AfxMessageBox("1");
                  pRecordset->Open(query,_variant_t((IDispatch*)pConnection,true),adOpenForwardOnly,adLockOptimistic,adCmdText); //here i am getting error
                  AfxMessageBox("2");
------
For ur info

_bstr_t CStr2bstr(CString str)
{
      BSTR _str=str.AllocSysString();
      _bstr_t bstrIntermediate(_str);
      return  bstrIntermediate;
}
0
Comment
Question by:sudhakar_koundinya
  • 5
  • 2
8 Comments
 
LVL 8

Expert Comment

by:AaronReams
ID: 12527838
i'm just guessing here but this

pConnection->Open ((_bstr_t)sConn,"","",adConnectUnspecified);      

looks like it should be

pConnection->Open (_bstr_t(sConn),"","",adConnectUnspecified);      
0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 12527869
No,

That didn't help me
0
 
LVL 8

Expert Comment

by:AaronReams
ID: 12527880
oh well, good luck.

btw, is that the line that's throwing the exception?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 12527907
Actually I am wroking with this statement only to other queries and they are working perfectly.

pConnection->Open ((_bstr_t)sConn,"","",adConnectUnspecified);      
0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 12527920
>> oh well, good luck.

I didn't get u

Actually I am getting error while opening recordset

AfxMessageBox("1");
//here i am getting error
               pRecordset->Open(query,_variant_t((IDispatch*)pConnection,true),adOpenForwardOnly,adLockOptimistic,adCmdText);
               AfxMessageBox("2");
0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 12527958
here is my full method

void CNewEmailContactDlg::FindFields()
{
      _RecordsetPtr pRecordset;
      _ConnectionPtr pConnection;
      AfxMessageBox(strSetMainSQL);
      _bstr_t query=CStr2bstr(strSetMainSQL);
            AfxMessageBox(bstr2CStr(query));
      bool connectionEstablished=false;
      strDatabaseFields.RemoveAll();
      try
    {
            CMASSMAILERApp* app=(CMASSMAILERApp*)AfxGetApp();
            CString appPath=app->GetApplicationPath ();
            pConnection.CreateInstance(__uuidof(Connection));
            pConnection->Provider = "Microsoft.Jet.OLEDB.4.0";
            //char *sConn=new char[250];
            CString sConn;
        sConn = appPath+"\\massmailer_database.mdb";
            pConnection->Open (_bstr_t(sConn),"","",adConnectUnspecified);            
            connectionEstablished=true;
            
      }

      catch(_com_error &e)
      {
            
            connectionEstablished=false;
            AfxMessageBox("First Chance of Error");

      }

      if(connectionEstablished)
      {
            try
            {
                  _bstr_t b_databaseText;
                  CString m_consu_Id,m_name,m_mailid;
                  CString strid;
      
                  AfxMessageBox("1");
                  pRecordset->Open(query,_variant_t((IDispatch*)pConnection,true),adOpenForwardOnly,adLockOptimistic,adCmdText);
                  AfxMessageBox("2");


                  pConnection->Execute(query,NULL,NULL);

                  Fields *flds=pRecordset->Fields;
                  Field *fld;
                  BSTR FldName;
                  long FldCount=flds->GetCount();
                  long Columns=FldCount;

                              int i=0;
                              
                     while(FldCount>0)
                     {
                         
                     fld=flds->GetItem( COleVariant((long)i));
                     fld->get_Name(&FldName);
                     CString strTmp=BSTR2CStr(FldName);               // Converts BSTR to String
                     strDatabaseFields.Add(strTmp);    // Get the Field Labels from the table
                    
                     i++;
                     FldCount--;
                     }
            }
            catch(_com_error &e)
            {      
                  AfxMessageBox(e.ErrorMessage());
                  AfxMessageBox(bstr2CStr(e.Description()));
                  AfxMessageBox("Second Chance of Error");
            }
      }
            
}
0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 12530483
I have found the error in my code. I haven't place below lines in my code

            pRecordset.CreateInstance(__uuidof(Recordset));
                  pRecordset->PutRefActiveConnection(pConnection);


Requesting the CS to delete this thread

Thanks
sudhakar
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12574326
Closed, 125 points refunded.

modulo
Community Support Moderator
Experts Exchange
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question