SQLExecute 始终以超过 8k 大小的参数返回"[Microsoft][SQL Server Native Client 10.0]String data, right truncation"

SQLExecute always returning "[Microsoft][SQL Server Native Client 10.0]String data, right truncation" in parameters more than 8k sized

本文关键字:Client Native Server SQL String truncation right data Microsoft 8k SQLExecute      更新时间:2023-10-16

当我执行SQLExecute函数时,当我的参数超过8k字节时,它总是返回"[Microsoft][SQL Server Native Client 10.0]字符串数据,右截断"。我将粘贴下面的代码。我正在尝试做的是:通过 SQL Server 2008 R2 中的 ODBC 驱动程序 (Visual C++ 2008) 通过存储过程将 XML 文件存储在声明为 varbinary(max) 的列中。SP 从 varchar 转换为 varbinary 调用SET @XML_FILE_BIN = CONVERT(VARBINARY(MAX), @XML_FILE)如果我尝试将整个 XML 粘贴到 SQL Server Management Studio 中,它可以正常工作。我认为SQLBindParameter中的绑定有问题。代码:

char* cXmlBuf; it contains my buffer
retcode = SQLBindParameter(
    hstmt,              //StatementHandle
    1,                  //ParameterNumber
    SQL_PARAM_INPUT,    //InputOutputType
    SQL_C_CHAR,         //ValueType
    SQL_CHAR,           //ParameterType
    SQL_DESC_LENGTH,    //ColumnSize
    0,                  //DecimalDigits
    cXmlBuf,            //ParameterValuePtr
    bufLenght,          //BufferLength
    &cbXml              //StrLen_or_IndPtr
);
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
    return;
SWORD id = 0;
SQLINTEGER cbId = 0;
retcode = SQLBindParameter(hstmt, 2, SQL_PARAM_OUTPUT, SQL_C_SSHORT, SQL_INTEGER, 0, 0, &id, 0, &cbId);
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
    return;
retcode = SQLPrepare(hstmt, (SQLCHAR*)"{CALL MY_STORE_PROC(?, ?)}", SQL_NTS);
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
    return;
retcode = SQLFreeStmt(hstmt, SQL_CLOSE); // Clear any cursor state
retcode = SQLExecute(hstmt);
//in this part retcode is -1 and "[Microsoft][SQL Server Native Client     
//10.0]String data, right truncation" is returned if my XML buffer
//has more than 8k

找到了!我声明SQLINTEGER cbXml = SQL_NTS;而不是SQLLEN cbXml = 0;谢谢。