SQLFetch()失败,返回SQLState 24000(无效游标)
SQLFetch() fails with the SQLState 24000 (Invalid Cursor)
首先,这个问题不是的重复
- SQLSTATE 24000-游标状态无效
- 无效的游标状态,SQLExecDirect中的SQL状态24000
- 使用unixOdbc-SQLSTATE[24000]的SELECT之一失败:游标状态无效
因为它发生在一个干净的单一SQL环境中,该环境以前从未执行过任何操作!
我正试图用准备好的SQL语句执行一个存储过程,该语句包含以下C++ODBC代码:
void ItemDBManager::UpgradeItem(SQLHSTMT hstmt, QUERY_UPGRADE_ITEM_PARAMS* upgradeItemParams)
{
// Preparing of the Query
RETCODE ret = SQLPrepare(hstmt, (UCHAR*)"{call dbo.upgrade_Item(?,?)}", SQL_NTS);
if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO)
{
// Get diagnostics for the error and log it to a file
ProcessSQLError(SQL_HANDLE_STMT, hstmt, "dbo.upgrade_Item failed!");
SQLFreeStmt(hstmt, SQL_CLOSE);
return;
}
// Binding of Parameters
SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SBIGINT, SQL_BIGINT, 0, 0, &upgradeItemParams->OldItemUniqueNumber, 0, NULL);
SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 0, 0, &upgradeItemParams->UpgradedItemUID, 0, NULL);
// Binding of the Result
SQLINTEGER cb[44];
fill_n(cb, 44, SQL_NTS);
ITEM newItem; // My struct to hold the data returned by the Stored Procedure
// Binding of result Columns
int coldIdx = 0;
SQLBindCol(hstmt, ++colIdx, SQL_C_SBIGINT, &storeItem.UniqueNumber, 0, &cb[colIdx]);
SQLBindCol(hstmt, ++colIdx, SQL_C_ULONG, &storeItem.AccountUniqueNumber, 0, &cb[colIdx]);
[...]
// Zeroing the resulting struct
memset(&newItem, 0x00, sizeof(ITEM));
// Execution of the Statement
ret = SQLExecute(hstmt);
if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO)
{
// Get diagnostics for the error and log it to a file
ProcessSQLError(SQL_HANDLE_STMT, hstmt, "dbo.upgrade_Item failed!");
SQLFreeStmt(hstmt, SQL_CLOSE);
return;
}
// Fetching of a single result row
ret = SQLFetch(hstmt);
if (ret == SQL_NO_DATA || (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO))
{
// <-- The Debugger enters here with the return code of -1 !!!!
// Get diagnostics for the error and log it to a file
ProcessSQLError(SQL_HANDLE_STMT, hstmt, "dbo.upgrade_Item failed!");
SQLFreeStmt(hstmt, SQL_CLOSE);
return;
}
[...] // Further Handling of the resulted ITEM Struct and freeing of the SQL Statement
}
调试器进入最后一个返回代码为-1
的IF语句,它是一个通用的SQL_ERROR。
通过获得错误的诊断Rect,我得到以下输出:
06-24 14:05:19| szSqlState = 24000
06-24 14:05:19| pfNativeError = 0
06-24 14:05:19| szErrorMsg = [Microsoft][ODBC SQL Server Driver]Invalid Cursorstatus
06-24 14:05:19| pcbErrorMsg = 58
06-24 14:05:19| ODBCRowNumber = -1
06-24 14:05:19| SSrvrLine = -1
06-24 14:05:19| SSrvrMsgState = 0
06-24 14:05:19| SSrvrSeverity = 0
06-24 14:05:19| SSrvrProcname =
06-24 14:05:19| SSrvrSrvname =
直接在微软的SQL管理工作室中执行查询给了我一个完美的结果,没有任何错误。
出现此错误的原因是什么?如何进一步调试它
此外,存储过程dbo.upgrade_Item
:的内容
-- Stored Procedure dbo.upgrade_Item
@i_OldStoreUID BIGINT,
@i_NewItemNum INT
AS
DECLARE @insertedIDs TABLE(Id BIGINT)
-- Updating of the ItemStore Table
INSERT INTO td_ItemStore (*my columns*)
OUTPUT INSERTED.UniqueNumber INTO @insertedIDs
SELECT *my columns*, @i_NewItemNum
FROM td_ItemStore
WHERE UniqueNumber = @i_OldStoreUID
-- Returning the new inserted Item
SELECT * FROM td_ItemStore WHERE UniqueNumber = (SELECT TOP 1 Id FROM @insertedStoreUIDs)
非常感谢您的帮助!
显然我遇到了与这个问题相同的问题:带有MSSQL的PDO返回无效的游标
问题出现在我的存储过程中。为了得到正确的光标,我不得不通过设置NOCOUNT ON
来禁用受影响行的输出
固定程序:
-- Stored Procedure dbo.upgrade_Item
@i_OldStoreUID BIGINT,
@i_NewItemNum INT
AS
BEGIN
SET NOCOUNT ON;
DECLARE @insertedIDs TABLE(Id BIGINT)
-- Updating of the ItemStore Table
INSERT INTO td_ItemStore (*my columns*)
OUTPUT INSERTED.UniqueNumber INTO @insertedIDs
SELECT *my columns*, @i_NewItemNum
FROM td_ItemStore
WHERE UniqueNumber = @i_OldStoreUID
-- Returning the new inserted Item
SELECT * FROM td_ItemStore WHERE UniqueNumber = (SELECT TOP 1 Id FROM @insertedStoreUIDs)
END
相关文章:
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 无法访问嵌套类.类的使用无效
- 如果用户输入无效,如何使用字符串变量-C++重复输入命令
- 如何解决错误:SCIP C++中的 SCIP 阶段无效 <10>
- 在没有参数列表的情况下使用模板名称"Event"无效,模板问题
- FFMPEG配置文件级别id大小无效
- 错误:从"int"到枚举c++的转换无效
- 如何修复此错误:className::className的无效使用
- 为什么将值返回函数传递给重载=运算符对运算符函数有效,而对其他运算符无效
- C++-模板嵌套类的引用初始化无效
- 错误:无效的预处理指令 #i 的意思是 #if?
- 多维数组 C++ 中数组下标的类型"int[int]"无效
- 在 C++ 中使用正则表达式错误时出现问题 括号表达式中的范围无效
- 从 'int' 到 'int*' CPP 的转换无效
- 如何接受 [ENTER] 键作为无效输入并发送错误消息
- 由于无效的 ValidateRgn() 子窗口不会收到WM_PAINT消息
- C++ PTHREADS - 无效转换无效*(*)()到无效*(*)(无效*)
- 声明为无效的变量或字段'...' Ardunio 编译器上的错误
- SQLSTATE 24000 - 无效的游标状态 ODBC VS c++
- SQLFetch()失败,返回SQLState 24000(无效游标)