How to solve the exception caused by too long update string of subsonic3.0 plug-in
This article mainly explains "how to solve the exception caused by the long update string of the subsonic3.0 plug-in". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to solve the exception caused by the long update string of the subsonic3.0 plug-in".
Open the project solution, enter DEBUG mode, get the operational data and submit it for tracking, and find that the submission generated: System.Data.SqlClient.SqlException (0x80131904): the incoming tabular data flow (TDS) remote procedure call (RPC) protocol flow is incorrect. Parameter 4 ("@ up_xxx"): the data length or metadata length of the data type 0xA7 is invalid.
Baidu found that the exception was caused by an overlong update string, so the Size of the parameter must be set to-1, so it is handled according to the following figure.
The copy 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
/ *
* revised by: Empty (AllEmpty)
* Modification instructions: modify the Bug caused by the long length of the submitted string
* exception message: System.Data.SqlClient.SqlException (0x80131904): the incoming tabular data flow (TDS) remote procedure call (RPC) protocol stream is incorrect.
* Parameter 4 ("@ up_xxx"): invalid data length or metadata length for data type 0xA7.
* /
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)
}
}
}
Thank you for reading, the above is the content of "how to solve the exception caused by the subsonic3.0 plug-in update string is too long". After the study of this article, I believe you have a deeper understanding of how to solve the problem of the exception caused by the subsonic3.0 plug-in update string is too long, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!