Re: Getting error DB_E_ERRORSINCOMMAND when I call execute for the 2nd time....

From: Ralph Krausse (gordingin_at_consiliumsoft-nospam.com)
Date: 06/14/04


Date: Mon, 14 Jun 2004 11:34:54 -0400

I seemed to have figured it out, at least one solution and I wish to share
the answer for anyone who runs into this problem in the furture... I just
got the parameter count and delete them.

  int iCount = m_pCommand->Parameters->GetCount();
  for(int i = 0; i < iCount; i++)
  {
   _variant_t vIndex((short)0);
   m_pCommand->Parameters->Delete(vIndex);
  }

"Ralph Krausse" <gordingin@consiliumsoft-nospam.com> wrote in message
news:uEyNoehUEHA.4048@TK2MSFTNGP12.phx.gbl...
> I created a class that uses the same _CommandPtr and _RecordsetPtr. Since
I
> will be make recurring function calls, I didn't want delete the objects
and
> recreate them using CreateInstance(). I call my first stored procedure, it
> works fine but when I call my second stored procedure, it fails and
returns
> a DB_E_ERRORSINCOMMAND. Now I can understand, I set my SP name, added
> parameters so technically those are still there when I set my new SP name
> and add my next parameters. I wish NOT to delete the object and recreate
it
> because of optimization, this will occur hundreds of times per minute so
is
> there a way to clear everything out?
>
>
>
>
>
> Function 1
>
> _ParameterPtr pParam1, pReturn;
>
> m_pCommand->CommandText = "sp_ Function1";
>
> m_pCommand->CommandType = adCmdStoredProc;
>
>
>
> pReturn = m_pCommand->CreateParameter ( _bstr_t (""), adInteger,
> adParamReturnValue, sizeof(int));
>
> m_pCommand->Parameters->Append (pReturn);
>
> pParam1 = m_pCommand->CreateParameter ( _bstr_t ("Param1"), adVarChar,
> adParamInput, strlen(pszParam1), (_bstr_t)pszParam1);
>
> m_pCommand->Parameters->Append (pParam1);
>
> m_pRecordset = m_pCommand->Execute(NULL, NULL, adCmdStoredProc);
>
>
>
>
>
> Function 2
>
> _ParameterPtr pParam1, pParam1, pReturn;
>
> m_pCommand->CommandText = "sp_ Function2";
>
> m_pCommand->CommandType = adCmdStoredProc;
>
>
>
> pReturn = m_pCommand->CreateParameter ( _bstr_t (""), adInteger,
> adParamReturnValue, sizeof(int));
>
> m_pCommand->Parameters->Append (pReturn);
>
> pParam1 = m_pCommand->CreateParameter ( _bstr_t ("Param1"), adVarChar,
> adParamInput, strlen(pszParam1), (_bstr_t)pszParam1);
>
> m_pCommand->Parameters->Append (pParam1);
>
> pParam2 = m_pCommand->CreateParameter ( _bstr_t ("Param2"), adVarChar,
> adParamInput, strlen(pszParam2), (_bstr_t)pszParam2);
>
> m_pCommand->Parameters->Append (pParam2);
>
> m_pRecordset = m_pCommand->Execute(NULL, NULL, adCmdStoredProc);
>
>
>
>
>
>
>
> The functions and m_pCommand and pRecordset are defined in a class so I
wish
> create them ONCE and reuse them. Calling Function 1 works, then calling
> Function 2 fails. To make sure I wasn't on the crack, I tested this by
> calling Function 2 first (which worked), then called Function 1, which
then
> failed. So I am pretty confident that the problem is that once I call
> Execute the 2nd time, 5 parameters have been added.
>
>
>
> Any help would be appreciated.
>
>
>
> Thanks
>
> Ralph Krausse
>
> www.consiliumsoft.com
>
> Use the START button? Then you need CSFastRunII...
>
> A new kind of application launcher integrated in the taskbar!
>
> ScreenShot - http://www.consiliumsoft.com/ScreenShot.jpg
>
>


Loading