c# – 在asp.net中执行存储过程时出错

c# – 在asp.net中执行存储过程时出错,第1张

概述我试图在后面的代码中执行asp.net中的存储过程.我试图传递的参数是strErrorMessage,其中包含值“传输无法连接到服务器.”. 执行查询时的错误消息是:传入的表格数据流(TDS)远程过程调用(RPC)协议流不正确.参数1(“@ errMessage”):数据类型0xE7具有无效的数据长度或元数据长度. 使用代码更新 try { ... ... 我试图在后面的代码中执行asp.net中的存储过程.我试图传递的参数是strErrorMessage,其中包含值“传输无法连接到服务器.”.

执行查询时的错误消息是:传入的表格数据流(TDS)远程过程调用(RPC)协议流不正确.参数1(“@ errMessage”):数据类型0xE7具有无效的数据长度或元数据长度.

使用代码更新

try    {        ...        ...        ...    }        catch (Exception ex)        {            ClIEntScript.RegisterStartupScript(GetType(),"alert","alert('Email was not sent - " + ex.Message + "');",true);            string strMessage = ex.Message;            string strStackTrace = ex.StackTrace;            strMessage = strMessage.Replace("\r\n","; ");            strMessage = strMessage.Replace("   ","");            strStackTrace = strStackTrace.Replace("\r\n","; ");            strStackTrace = strStackTrace.Replace("   ","");            AppErrorLog(strMessage,strStackTrace);            return false;        }    protected voID AppErrorLog(string strErrorMessage,string strErrorStackTrace)    {        sqlConnection conErrLog = new sqlConnection(strConn);        string sql = "usp_AppErrorLog_AddRecord";        sqlCommand cmdErrLog = new sqlCommand(sql,conErrLog);        conErrLog.open();        try        {            cmdErrLog.CommandType = CommandType.StoredProcedure;            cmdErrLog.Parameters.Add(new sqlParameter("@errMessage",sqlDbType.NVarChar,8000));            cmdErrLog.Parameters["@errMessage"].Value = strErrorMessage;            cmdErrLog.Parameters.Add(new sqlParameter("@errStackTrace",8000));            cmdErrLog.Parameters["@errStackTrace"].Value = strErrorStackTrace;            cmdErrLog.Parameters.Add(new sqlParameter("@userID",sqlDbType.VarChar,12));            cmdErrLog.Parameters["@userID"].Value = User.IDentity.name;            sqlDataAdapter ada = new sqlDataAdapter(cmdErrLog);            cmdErrLog.ExecuteNonquery();        }        catch(Exception e)        {            ClIEntScript.RegisterStartupScript(GetType(),"alert('AppErrorLog - " + e.Message + "');",true);        }        finally        {            conErrLog.Close();        }    }

表中的列数据类型是nvarchar(MAX).
任何想法如何解决这个问题?

解决方法 这部分“数据类型0xE7具有无效的数据长度”使我相信参数strErrorMessage被指定为具有比sql Parameter DataType可以处理的数据长度更多的数据长度.

Here是Microsoft支持文章,可能会有所帮助.

根据这篇文章

When you specify an NVarChar parameter
with sqlParameter.Size between 4001
and 8000,sqlClIEnt will throw the
following exception.

The incoming tabular data stream (TDS)
remote procedure call (RPC) protocol
stream is incorrect. Parameter
(“@”): Data type 0xE7
has an invalID data length or Metadata
length.

To work around this issue,use one of
the following options:

· Set sqlparamter.size
property to -1 to ensure that you are
getting the entire data from the
backend without truncation.

· When working with String
DbTypes whose sizes are greater than
4000,explicitly map them to another
sqlDBType like NText instead of using
NVarchar(which also is the default
sqlDBType for strings).

· Use a value that is not between 4001 and 8000 for sqlparameter.size.

总结

以上是内存溢出为你收集整理的c# – 在asp.net中执行存储过程时出错全部内容,希望文章能够帮你解决c# – 在asp.net中执行存储过程时出错所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1224501.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存