Invalid Pointer Exception

_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;
}
LVL 14
sudhakar_koundinyaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AaronReamsCommented:
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
sudhakar_koundinyaAuthor Commented:
No,

That didn't help me
0
AaronReamsCommented:
oh well, good luck.

btw, is that the line that's throwing the exception?
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

sudhakar_koundinyaAuthor Commented:
Actually I am wroking with this statement only to other queries and they are working perfectly.

pConnection->Open ((_bstr_t)sConn,"","",adConnectUnspecified);      
0
sudhakar_koundinyaAuthor Commented:
>> 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
sudhakar_koundinyaAuthor Commented:
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
sudhakar_koundinyaAuthor Commented:
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
moduloCommented:
Closed, 125 points refunded.

modulo
Community Support Moderator
Experts Exchange
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.