Recently, the company's customer service submitted a BUG saying that some of the products could not be updated while updating the product details. Some of them have been unavailable for a while, so they are temporarily put down. This problem has just occurred again, so I processed it immediately.
Open the project solution, enter the DEBUG mode, and track the submitted operation data. The System is generated during the submission. data. sqlClient. sqlException (0x80131904): The input table format data stream (TDS) Remote Procedure Call (RPC) protocol stream is incorrect. Parameter 4 ("@ up_xxx"): The data length of data type 0xA7 or the metadata length is invalid.
Baidu finds that the exception is caused by a long string update. You must set the parameter Size to-1.
Copy codeThe Code is as follows:
Private static void AddParams (DbCommand cmd, QueryCommand qry)
{
If (qry. Parameters! = Null)
{
Foreach (QueryParameter param in qry. Parameters)
{
DbParameter p = cmd. CreateParameter ();
P. ParameterName = param. ParameterName;
P. Direction = param. Mode;
P. DbType = param. DataType;
/*
* Modifier: Empty (AllEmpty)
* Modification Description: Modify the Bug that the submitted string length is too long.
* Exception information: System. Data. SqlClient. SqlException (0x80131904): The input table format Data stream (TDS) Remote Process Call (RPC) protocol stream is incorrect.
* Parameter 4 ("@ up_xxx"): The data length of data type 0xA7 or the metadata length is invalid.
**************************************** *****/
If (param. DataType. ToString () = "AnsiString ")
{
P. Size =-1;
}
// Output parameters need to define a size
// Our default is 50
If (p. Direction = ParameterDirection. Output | p. Direction = ParameterDirection. InputOutput)
P. Size = param. Size;
// Fix for NULLs as parameter values
If (param. ParameterValue = null)
{
P. Value = DBNull. Value;
}
Else if (param. DataType = DbType. Guid)
{
String paramValue = param. ParameterValue. ToString ();
If (! String. IsNullOrEmpty (paramValue ))
{
If (! ParamValue. Equals ("DEFAULT", StringComparison. InvariantCultureIgnoreCase ))
P. Value = new Guid (paramValue );
}
Else
P. Value = DBNull. Value;
}
Else
P. Value = param. ParameterValue;
Cmd. Parameters. Add (p );
}
}
}