• SqlException 当前命令发生了严重错误 应放弃任何可能产生的结果


    今天在信息发布功能时出现了一个怪异的错误(时而出错,时而不会):

    System.Data.SqlClient.SqlException: 当前命令发生了严重错误。应放弃任何可能产生的结果。

      >>具体的错误提示如下所示:

    System.Data.SqlClient.SqlException: 当前命令发生了严重错误。应放弃任何可能产生的结果。
    当前命令发生了严重错误。应放弃任何可能产生的结果。
       在 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
       在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
       在 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
       在 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
       在 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
       在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
       在 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
       在 System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
       在 Microsoft.Practices.EnterpriseLibrary.Data.Database.DoExecuteNonQuery(DbCommand command)
       在 Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteNonQuery(DbCommand command)
       在 Core.DAL.Article.Update(Article model) 位置 E:WorksPortalCoreDALArticle.cs:行号 149
       在 Core.BLL.Article.Update(Article model) 位置 E:WorksPortalCoreBLLArticle.cs:行号 37
       在 LWDocService.Portal.Admin.ArticleEdit.btnSubmit_Click(Object sender, EventArgs e) 位置 E:WorksPortalAdminArticleEdit.aspx.cs:行号 86
       在 System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       在 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       在 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

       >>具体经验判断应该是字段长度的问题,但经网上搜索有些说是没有安装SQL Server 2000 SP1补丁导致的,属于SQL Server的一个bug,但我将数据库附加到MS SQL Server 2005然后再运行时还是出现错误了,而这次的错误提示却与SQL Server 2000不同:

    System.Data.SqlClient.SqlException: 传入的表格格式数据流(TDS)远程过程调用(RPC)协议流不正确。参数 15 ("@Content"): 数据类型 0xA7 的数据长度或元数据长度无效。

       >>从错误的提示上看应该可以比较直观地判断出是字段Content的长度问题,而为什么SQL Server 2000与SQL Server 2005不同的数据库版本竟会有不同的错误提示呢?大家有兴趣或知道的,请告知 :),在这里老林只想解决出现的问题.....

       >>好了,知道问题的根源解决就不困难了,

      原来的代码:

    db.AddInParameter(dbCommand, "Content", DbType.AnsiString, model.Content);
    

     改为现在的代码:

     db.AddInParameter(dbCommand, "Content", DbType.String, model.Content);

        >>那么DbType.AnsiString与DbType.String有任何区别呢?

    经查MSDN资料,https://msdn.microsoft.com/zh-cn/library/system.data.dbtype%28VS.80%29.aspx?f=255&MSPPError=-2147217396:

    AnsiString——非 Unicode 字符的可变长度流,范围在 1 到 8,000 个字符之间。

    String——表示 Unicode 字符串的类型。

       >>大家看到了吗?AnsiString最大的范围是在8000个字符之内,如果你的文章内容太多那将可能出错误。

      

     原文链接:SqlException 当前命令发生了严重错误 应放弃任何可能产生的结果

        >>小广告: 八爪鱼招标网 大家多给意见哦

      

  • 相关阅读:
    人人都是架构师:分布式系统架构落地与瓶颈突破
    Node.js区块链开发
    MDD:使用模型驱动开发方式进行快速开发(多图预警)
    MDSF:模型驱动开发(MDD)介绍 | 一群共同享有幸福生活的成长伙伴
    SLF4J with Logback in a Maven Project | Mograblog
    Spring MVC集成slf4j-logback
    SLF4J和Logback日志框架详解
    Python中国社区
    致远互联官网_致远软件_协同 _OA_OA系统_OA办公系统_协同管理软件及云服务领导供应商-致远软件官网
    新精英博客_公司博客_官方公告
  • 原文地址:https://www.cnblogs.com/samlin/p/SqlException_AnsiString_TDS.html
Copyright © 2020-2023  润新知