【问题标题】:Value was either too large or too small for an Int16 after many years多年后的 Int16 值要么太大要么太小
【发布时间】:2016-11-16 04:55:35
【问题描述】:

我的一个应用程序从 2005 年开始运行。现在它给出了下面提到的错误。

我不知道发生了什么。有人遇到过这样的问题吗?

Server Error in '/' Application.
Value was either too large or too small for an Int16.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
Exception Details: System.Exception: Value was either too large or too small for an Int16.
Source Error: 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace: 
[Exception: Value was either too large or too small for an Int16.]
   Attach_DL.Generatekey() +121
   Attach_BL.GenerateKey() +12
   Picture.AddAttachments(String _attachpath, String _attachpathDB) +289
   Picture.Btnsave_Click(Object sender, EventArgs e) +1416
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927

【问题讨论】:

  • 我无法仅从堆栈跟踪中得知太多信息(即,提供堆栈跟踪引用的代码会有所帮助)我会指出 Int16 的最大大小是 @ 987654322@(正或负)。根据堆栈跟踪,您的应用程序正试图将大于或小于该值的内容放入 Int16 变量中。
  • 也许您在应用程序中使用的数据类型为 Int16 的字段已超过值 32767。
  • 请贴出Attach_DL.Generatekey()的源码

标签: c# asp.net visual-studio deployment iis-7


【解决方案1】:

怀疑结果包含较大的值,Int16 无法保存。所有类型的整数都有不同的以下存储容量范围

Int 16 -- (-32768 to +32787)

【讨论】:

  • 我多年来一直保存相同的记录。没有我给出巨大数字的领域。为什么其他数据和以前一样保存?
  • @MuhammadFahad 主键?
  • 没有兄弟。实际上我的问题是为什么它在多年后使用我们之前保存的相同数据集给出错误。
  • @MuhammadFahad 是的,他的意思是主键值可能已经超过 32787,因为你现在有那么多记录。
【解决方案2】:

自 2005 年以来,您的字段可能会增加,现在的值超过 32787。

EF 根据可能给出 int16 的 DB 类型 numeric(5) 生成字段,即使它可以容纳 99999

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-27
    相关资源
    最近更新 更多