当我执行SQLExecute函数时,当我的参数超过8k字节时,它总是返回"[Microsoft][SQL Server Native Client 10.0]String data, right truncation" . 我将粘贴下面的代码 . 我正在尝试做的事情:在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
1 回答
找到了!我宣布
SQLINTEGER cbXml = SQL_NTS;
而不是SQLLEN cbXml = 0;
谢谢 .