Met*_*eat 2 sql sql-server monodevelop unity-game-engine executenonquery
我目前正在使用SQL Server 2014中的C#脚本更新和读取值.当使用SQlCommand执行InitQuery时,它会在运行脚本时弹出错误:
IndexOutOfRangeException:数组索引超出范围.
Mono.Data.Tds.Protocol.TdsComm.AppendInternal(Int16 s)
Mono.Data.Tds.Protocol.TdsComm.Append(System.String s)
Mono.Data.Tds.Protocol.Tds70.WriteRpcParameterInfo(Mono.Data.Tds. TdsMetaParameterCollection参数)
Mono.Data.Tds.Protocol.Tds70.ExecRPC(TdsRpcProcId rpcId,System.String sql,Mono.Data.Tds.TdsMetaParameterCollection参数,Int32超时,布尔值wantResults)
Mono.Data.Tds.Protocol.Tds70.Execute( System.String commandText,Mono.Data.Tds.TdsMetaParameterCollection参数,Int32 timeout,Boolean wantResults)
System.Data.SqlClient.SqlCommand.Execute(Boolean wantResults)
System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
(wrapper remoting-invoke- with-check)
System.Data.SqlClient.SqlCommand:ExecuteNonQuery()
Database.DataBaseConnection.Update()(在Assets/DataBaseConnection.cs:674)
我计算了SqlCommand它有多少个字符,它是8,125个字符(没有空格),10,874个字符(带空格).
有198个参数,但我想这不是由于那个,因为在某处我读到单个查询的最大参数量是2000,我是对的吗?
我减少了参数的数量(直到20个参数),因此,命令长度和它的作用就像一个魅力(875个字符没有空格和1,221个字符带空格).
总而言之,我的问题是:SqlCommandSQL Server 2014中查询的最大长度是多少?在SQL Server 2008中?
我的代码示例:
//New command to update values in input table in sql server
using (SqlCommand command = new SqlCommand("UPDATE DigitalInputs" +
" SET Value = CASE Name" +
" WHEN @LI_Input_Variable1_Name THEN @LI_Input_Variable1_Value" +
" WHEN @LI_Input_Variable2_Name THEN @LI_Input_Variable2_Value" +
" WHEN @LI_Input_Variable3_Name THEN @LI_Input_Variable3_Value" +
//It is the same from 3 till 99
" WHEN @LI_Input_Variable99_Name THEN @LI_Input_Variable99_Value" +
" END" +
" WHERE Name IN (@LI_Input_Variable1_Name, @LI_Input_Variable2_Name, @LI_Input_Variable3_Name,
//It is the same from 3 till 99
@LI_Input_Variable99_Name);", connection))
{
command.Parameters.Add(new SqlParameter("LI_Input_Variable1_Name", "LI_Input_Variable1"));
command.Parameters.Add(new SqlParameter("LI_Input_Variable1_Value", LI_Input_Variable1.ToString()));
command.Parameters.Add(new SqlParameter("LI_Input_Variable2_Name", "LI_Input_Variable2"));
command.Parameters.Add(new SqlParameter("LI_Input_Variable2_Value", LI_Input_Variable2.ToString()));
command.Parameters.Add(new SqlParameter("LI_Input_Variable3_Name", "LI_Input_Variable3"));
command.Parameters.Add(new SqlParameter("LI_Input_Variable3_Value", LI_Input_Variable3.ToString()));
//It is the same from 3 till 99
command.Parameters.Add(new SqlParameter("LI_Input_Variable99_Name", "LI_Input_Variable99"));
command.Parameters.Add(new SqlParameter("LI_Input_Variable99_Value", LI_Input_Variable99.ToString()));
command.ExecuteNonQuery(); //Execute the non query
}
Run Code Online (Sandbox Code Playgroud)
后编辑: 我正在用MonoDevelop 5.9.6实现这个脚本.在Unity3D中
小智 6
让我回答你问的问题:SqlCommand查询的最大长度是多少?
语句的最大大小为65536*网络数据包大小 - 默认情况下大约为1500字节.算一算 - 大概是90MB.
超过这个,但不会导致你的错误.但这是你问过的问题.