• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 721
  • Last Modified:

C++ ADO stored procedure CALL format

All,

I am trying to pass 4 values to a EXECUTE stored procedure and then call open.  I get an exception thrown saying that it is expecting the name of the table.

Can anyone help me reformat this?

I have tried the rs.Execute("name"); command and it does not throw an exception but am not able to get at the returned values from the DB table.

thanks in advance....

regards,

Ken



CString tempstr, _tool, _pm, _device, _operation;
      _tool = "A";
     _pm = "2";
     _device"all";
     _operation = "all"    
tempstr.Format("DECLARE  @slope float, @intercept float,  @angle int\n"
"EXECUTE sp_IONMILL_BEAMANGLE '%s', '%s', '%s', '%s' , @slope , @intercept, @angle",
                              _tool, _pm, _device, _operation);
      

/****************************
  Open DSN database
****************************/
CDatabase *pWaferDB=new CDatabase();
if(pWaferDB->OpenEx("DSN=RecipeDatabase;Trusted Connection = trusted") == 0)
{
      errMsg="Can not open tblBeamAngle table from RecipeDatabase";
      AfxMessageBox(errMsg);
      delete pWaferDB;
      pWaferDB=NULL;
      return -99;
}

/****************************
  Open Table with SQL query
****************************/      
CRecordset rs(pWaferDB);
if(!rs.Open(CRecordset::forwardOnly, tempstr))
{
      errMsg = "Can not open tblBeamAngle table from RecipeDatabase";
      AfxMessageBox(errMsg, MB_OK);
      pWaferDB->Close();
      rs.m_pDatabase=pWaferDB=NULL;
      delete pWaferDB;
      return -99;
}
0
kenhoppe
Asked:
kenhoppe
  • 2
1 Solution
 
nmcdermaidCommented:
Are you calling sp_IONMILL_BEAMANGLE, and passing in four parameters, and expecting to get three back?

In a different language, the general process is:


Create a 'command object'
Give the 'command object'  a connection
Tell the command object that its sp is called sp_IONMILL_BEAMANGLE
populate the parameter collection of the command object (with three input parameters and four output parameters)
execute the command
retrieve the four output parameters from the parameters collection.

However you are treating it as a recordset rather than an SP. In this case you to change the submitted SQL to something more like this:

SET NOCOUNT ON
DECLARE  @slope float, @intercept float,  @angle int
EXECUTE sp_IONMILL_BEAMANGLE '%s', '%s', '%s', '%s' , @slope , @intercept, @angle
SELECT @slope float, @intercept float,  @angle


(of course '%s', '%s', '%s', '%s' is not valid T-SQL syntax but you get the idea)


Lastly you MUST make sure that the first line of the sp_IONMILL_BEAMANGLE stored procedure is SET NOCOUNT ON

0
 
kenhoppeAuthor Commented:
All,

Is it better to use a RecordSet or SmartPointers to call a stored procedure using C++?  I am passing 4 parameters to the in put and recieving 3 in return.

thanks in advance..

Ken
0
 
nmcdermaidCommented:
I dont't know what a smartpointer is but in VB, if you are not expecting a table back, only parameterd, then it is indeed best to NOT use a recordset - use the command object with the parameters collection.

This may be of assistance:

http://www.codersource.net/c++_ado_stored_procedure.html


0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now