C++ ADO stored procedure CALL format

Posted on 2007-10-08
Last Modified: 2013-11-20

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....



CString tempstr, _tool, _pm, _device, _operation;
      _tool = "A";
     _pm = "2";
     _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";
      delete pWaferDB;
      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);
      delete pWaferDB;
      return -99;
Question by:kenhoppe
    LVL 30

    Accepted Solution

    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:

    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


    Author Comment


    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..

    LVL 30

    Expert Comment

    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:


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
    Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
    This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

    733 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now