我正在尝试调用存储过程将数据插入表并返回一个值。我得到一个返回码 99,上面写着 SQL_NEED_DATA。我正在使用 Visual Studio 2008 和 SQL Server Native Client 11 驱动程序。代码摘录:
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, &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, &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, &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, &exID, 0, &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, &dsOrderDate, 0, &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(), &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(), &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) &NoOfItemsExtracted, 0, &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) &Status, 0, &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) &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) &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) &migrationSts, 0, &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);
SQL Execute 之前的所有语句都返回 rc=0。我尝试连接到 db 并执行一个简单的 SQL 语句来插入数据,它是成功的。但是在运行程序的情况下失败。请帮我解决这个问题。