- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
首先这个问题不是重复的:
因为它发生在一个干净的单一 SQL 环境中,之前没有执行任何东西!
我正在尝试使用以下 C++ ODBC 代码使用准备好的 SQL 语句执行存储过程:
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 =
直接在 Microsoft 的 SQL Management Studio 中执行查询给我一个完美的结果,没有任何错误。
这个错误的原因是什么?如何进一步调试?
另外存储过程 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)
非常感谢任何帮助!
最佳答案
显然我遇到了与这个问题相同的问题:PDO with MSSQL returns Invalid Cursor
问题出在我的存储过程中。为了获得正确的游标,我必须通过设置 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
关于c++ - SQLFetch() 失败,SQLState 24000(无效游标),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31027017/
我正在使用 Oracle 数据库,并且想获取一个包含 3000 万条记录的表。 library(RODBC) ch <- odbcConnect("test", uid="test_user",
全部, 我正在尝试创建一个连接到 MS SQL Server (2012) 的程序。该程序将执行一些 SELECT 查询。 当我尝试使用这样的代码时: ret = SQLBindCol( stmt_t
我的类(class)有这样的结构: struct CommentData { GUID CommentID; GUID GroupID; wc
与 SQL_API SQLFetch 相比,使用 SQL_API SQLFetchScroll 是否有任何性能提升?我正在处理性能问题(需要从数据库加载太多数据)并发现该应用程序使用 SQLFetch
for _item in file_list: for col in cursor.execute("select column1,column2 from tbl"): if
首先这个问题不是重复的: SQLSTATE 24000 - Invalid Cursor State Invalid cursor state, SQL state 24000 in SQLExecD
我有 2 台电脑。 第一个 (A) 安装了 Windows Server 2003 和 SQL Server 2000。此计算机上存在一个数据库。此数据库已添加到具有 SQLServer 驱动程序版本
我是一名优秀的程序员,十分优秀!