944,142 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 3466
  • C RSS
Jul 21st, 2006
0

Getting "DB_E_ERRORSINCOMMAND" even when execute is successful

Expand Post »
When trying to set the 'max server memory' of a database I use the stored procedure (SP_COFIGURE) as follows:
  1. _bstr_t bstrCommandText = OLESTR("SP_CONFIGURE 'max server memory',");
  2. bstrCommandText = bstrCommandText + bstrServerMemory; // where bstrServerMemory = {"128" (1)}
  3. // looks like = {"SP_CONFIGURE 'max server memory',128" (1)}
  4.  
  5. iCmd->CommandText = bstrCommandText;
  6. iCmd->Execute(NULL, NULL, adCmdText); // This line generate an error
  7.  
  8. iCmd->CommandText = L"RECONFIGURE";
  9. iCmd->Execute(NULL, NULL, adCmdText);
However that code generates an except (access violation) on the line that has the comment (above) - not knowing why I changed the code (shown below) to the following so I could "catch" the actual error message and see what was going on...
  1. _bstr_t bstrCommandText = OLESTR("SP_CONFIGURE 'max server memory',");
  2. bstrCommandText = bstrCommandText + bstrServerMemory;
  3.  
  4. iCmd->CommandText = bstrCommandText;
  5. try
  6. {
  7. iCmd->Execute(NULL, NULL, adCmdText);
  8. }
  9. catch (_com_error cex)
  10. {
  11. int i; // just to put something
  12. }
  13.  
  14. iCmd->CommandText = L"RECONFIGURE";
  15. iCmd->Execute(NULL, NULL, adCmdText);
  16. }
Now this is much better but has me really confused ..??.. - the error caught (cex) is "DB_E_ERRORSINCOMMAND" - which is odd because it seems to work fine in SQL 2000 itself (Qeury analyzer) just not run via-code as such...
But that isn't the oddest part - if I continue after the exception and then check the server memory settings they have been changed successfully...
So the code WORKS but still throws an error "DB_E_ERRORSINCOMMAND" ... Why? If it works (because I can guarantee that it is correctly changing the max server memory as expected, tested this many times with different values) then why would it send back an error message?
What exactly does it mean? How can I get around this? I don't like my current fix (try/catch that just bypasses the error) - what if there is a REAL error one day? This is really an odd problem and I did some research on the net and couldn't find anything really similar - a few people mention using SET NOCOUNT ON (but I can't edit SP_CONFIGURE)...
Also - this only happens the FIRST TIME it is run, all subsequent times there is NO exception (cex) generated, no "DB_E_ERRORSINCOMMAND" ... this only happens the first time I try to make the changes...
Do I need to Initialize something first? I tried running a "RECONFIGURE" before and after - didn't make a difference...
And I haven't seen a "CONFIGURE" or "INITIALIZE" option - or whatnot like that ... I thought the problem could be that it was returning an empty row/column ... but that is just a theory...

Any help, comments, or hints would be greatly appreciated - I am really at a loss...
Thanks,
Similar Threads
Reputation Points: 9
Solved Threads: 0
Light Poster
Shaitan00 is offline Offline
38 posts
since Jul 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: problems in output ....
Next Thread in C Forum Timeline: Ellips arugument





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC