title: SQL Server - Calling Stored Procedures using C++ ODBC
body: <p>I'm trying to call a stored procedure to insert data into a table and return a value. I'm getting a return code 99 which says SQL_NEED_DATA. I'm using Visual Studio 2008 and SQL Server Native Client 11 driver. 
  Code extract:</p>
  
  <pre><code>rc=SQL_SUCCESS; 
  SQLINTEGER exID;
  SQLINTEGER cdexFolderName = SQL_NTS;
  SQLINTEGER cbexRootPath = SQL_NTS;
  SQL_DATE_STRUCT dsOrderDate ;
  SQLINTEGER cbOrderDate = 0;
  rc=SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &amp;hEnv);
  
  if(rc==SQL_SUCCESS)
  rc=SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION,(SQLPOINTER)SQL_OV_ODBC3, 0); 
  if(rc==SQL_SUCCESS)
  rc=SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &amp;hConn);
  rc = SQLDriverConnect (hConn, NULL, (SQLCHAR*) "DSN=TWPDEV;Trusted_Connection=yes;", 
                  SQL_NTS, retconstring, 1024, NULL,SQL_DRIVER_NOPROMPT);
  rc = SQLAllocHandle(SQL_HANDLE_STMT, hConn, &amp;hStmt);
  
  if (!(rc==0 || rc==1))
  show_error(SQL_HANDLE_DBC, hConn);
  rc = SQLBindParameter(hStmt, 1, SQL_PARAM_OUTPUT, SQL_C_SLONG, 
                  SQL_INTEGER, 0, 0, &amp;exID, 0, &amp;cbexID);
  if (!(rc==0 || rc==1))
  show_error(SQL_HANDLE_STMT, hStmt); 
  rc = SQLBindParameter(hStmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, 
          SQL_LONGVARCHAR, sizeof(dsOrderDate), 0, &amp;dsOrderDate, 0, &amp;cbOrderDate);
  if (!(rc==0 || rc==1))
  show_error(SQL_HANDLE_STMT, hStmt); 
  rc = SQLBindParameter(hStmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, 
                  SQL_LONGVARCHAR, 50, 0, (SQLPOINTER) ExtractionFolderName.c_str(), ExtractionFolderName.length(), &amp;cdexFolderName);
  if (!(rc==0 || rc==1))
  show_error(SQL_HANDLE_STMT, hStmt); 
  
  rc = SQLBindParameter(hStmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, 
                  SQL_LONGVARCHAR, 50, 0, (SQLPOINTER) ExtractionRootPath.c_str(), ExtractionRootPath.length(), &amp;cbexRootPath);
  if (!(rc==0 || rc==1))
  show_error(SQL_HANDLE_STMT, hStmt); 
  
  
  rc = SQLBindParameter(hStmt, 5, SQL_PARAM_INPUT, SQL_C_SLONG, 
                  SQL_INTEGER, 0, 0, (SQLPOINTER) &amp;NoOfItemsExtracted, 0, &amp;cbnumItemsExtracted);
  if (!(rc==0 || rc==1))
  show_error(SQL_HANDLE_STMT, hStmt); 
  rc = SQLBindParameter(hStmt, 6, SQL_PARAM_INPUT, SQL_C_SLONG, 
                  SQL_INTEGER, 0, 0, (SQLPOINTER) &amp;Status, 0, &amp;cbstatus);
  if (!(rc==0 || rc==1))
  show_error(SQL_HANDLE_STMT, hStmt); 
  rc = SQLBindParameter(hStmt, 7, SQL_PARAM_INPUT, SQL_C_SLONG, 
                  SQL_INTEGER, 0, 0, (SQLPOINTER) &amp;instanceID, 0, NULL);
  if (!(rc==0 || rc==1))
  show_error(SQL_HANDLE_STMT, hStmt); 
  
  rc = SQLBindParameter(hStmt, 8, SQL_PARAM_INPUT, SQL_C_SLONG, 
                  SQL_INTEGER, 0, 0, (SQLPOINTER) &amp;sourceID, 0,NULL);
  if (!(rc==0 || rc==1))
  show_error(SQL_HANDLE_STMT, hStmt); 
  
  rc = SQLBindParameter(hStmt, 9, SQL_PARAM_INPUT, SQL_C_SLONG, 
                  SQL_INTEGER, 0, 0, (SQLPOINTER) &amp;migrationSts, 0, &amp;cbmigStatus);
  if (!(rc==0 || rc==1))
  show_error(SQL_HANDLE_STMT, hStmt);     
  
  rc = SQLPrepare (hStmt, (SQLCHAR*) "{? = call dbo.procInsertExtraction(?,?,?,?,?,?,?,?)}", SQL_NTS);
  if (!(rc==0 || rc==1))
  show_error(SQL_HANDLE_STMT, hStmt);
  
  rc = SQLExecute(hStmt);
          if (!(rc==0 || rc==1))
              show_error(SQL_HANDLE_STMT, hStmt);
  </code></pre>
  
  <p>All the statements until SQL Execute are returning rc=0. I'm tried connecting to db and executed a simple SQL statement to insert data, it was successful. But failing in case of running a procedure.
  Please help me in resolving this.</p>