【问题标题】:Debug problem with asp.net VS2005asp.net VS2005的调试问题
【发布时间】:2010-01-20 15:54:47
【问题描述】:

我从其他开发人员那里接手的 asp.net 2.0 应用程序遇到了问题(这意味着我对代码知之甚少)。它引发了一个未处理的异常,但我无法获得任何确切发生异常的源信息,并且调试单步执行源突然以显示反汇编代码的唯一选项结束。

我还能在 VS2005 或 IIS 中做些什么来找出异常发生的确切位置吗?

下面是 IIS 错误消息的输出(通常显示源文件、行号等,但在这种情况下不显示)。

谢谢。

String or binary data would be truncated. 
The statement has been terminated. 
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.Data.SqlClient.SqlException: String or binary data would be truncated. 
The statement has been terminated.

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: 


[SqlException (0x80131904): String or binary data would be truncated. The statement has been terminated.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1950890
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4846875
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392
   System.Data.SqlClient.SqlDataReader.SetMetaData(_SqlMetaDataSet metaData, Boolean moreInfo) +125
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1908
   System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33
   System.Data.SqlClient.SqlDataReader.get_MetaData() +83
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +141
   System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12
   System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +10
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +130
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +287
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +92
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1297
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +19
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
   System.Web.UI.WebControls.GridView.DataBind() +4
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +72
   System.Web.UI.Control.EnsureChildControls() +87
   System.Web.UI.Control.PreRenderRecursiveInternal() +44
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082 

【问题讨论】:

  • 澄清:我知道 SQL 错误消息的含义。我只是不知道它来自哪里。该错误仅在加载应用程序中的一个页面时发生-所有其他页面都可以正常工作。在 VS 中进行调试时,它会在该页面的 Page_Load() 关闭 } 之后立即切换到程序集视图,所以我不知道错误来自哪里。

标签: .net asp.net sql debugging visual-studio-2005


【解决方案1】:

问题可能出在 VS 本身。在过去遇到此类问题时,我的问题有时会随着 VS 重新启动或重新启动而消失。假设这没有帮助:

我的猜测是 VS 可能没问题,而您使用的数据访问层 (DAL) 是问题所在。它似乎正在尝试处理错误,但做得不是很好。我无法从堆栈跟踪中看出,但您是在为您的 DAL 引用另一个 .NET 库,还是使用第 3 方 DAL?在第一种情况下,您应该能够运行它,放入断点,然后运行您的顶级代码。你应该能够达到你的断点。如果这是第 3 方 DAL,那将无法正常工作。

如果您根本无法单步执行您的 DAL 代码,那么您必须:

  1. 分析堆栈跟踪并尝试拼凑正在发生的事情。您确实对堆栈跟踪中的第一行有一个很好的线索:有些东西正试图将太大的数据放入太小的数据结构中。如果这是一个 write 过程,那么太小可能是数据库中的一个字段——将您正在使用的数据与它的去向进行比较。如果这是一个 read 进程,那么小东西就是一个中间 sql UDF 或过程。
  2. 使用 SQL Server Profiler 查看到底发生了什么。 (这当然假设您使用的是 SQL 服务器。)如果您以前没有使用过该工具,那么现在是开始的好时机。它将允许您解决此类问题。即使在处理具有良好错误处理的代码时,该工具也非常适合解决生产问题。使用 Profiler,您将能够看到正在发生的 sql 操作,并查看发生错误的位置。

【讨论】:

  • DAL 代码包含在项目中,也设置为调试模式编译。虽然调试器仍在单步执行代码,但它实际上也进入了 DAL 源代码,只是在发生异常时没有。我将开始查看 DAL 代码,看看那里的断点是否有帮助,并阅读服务器分析器。这也可以远程运行,因为我可能无法直接访问 sql server 机器。
  • Profiler 绝对可以远程运行。如果您的机器上安装了 sql server 客户端工具,您可能拥有它。唯一潜在的问题是,如果你有 DB-nazis 怀疑地问“你为什么需要它?那是我们的工作。”或者谁不会授予您跟踪权限。
  • "only" 我花了半天时间才获得了追踪所需的权限。它真的很有帮助。通过跟踪,我很快发现一个特定的存储过程是原因(将变量字段声明为太小的 varchar,因此截断错误消息)。所以感谢分析器的提示 - 现在我想知道为什么我以前从未使用过它;)
【解决方案2】:

嗯,这个错误信息看起来很熟悉。 您正在尝试插入一个对于数据库中的列来说太大的值。它可以是字符串或数字或其他东西。但是您必须能够根据触发错误时的操作来弄清楚这一点。

为了调试正在发生的事情,您需要转到 Debug -> Attach to process。并选择所有 w3wp.exe 进程(要查看它们,您可能需要勾选“显示所有用户的进程”和“显示所有会话中的进程”)。此外,您需要确保您的网站是在调试构建配置中构建的,而不是在发布中构建的。

希望对你有帮助

【讨论】:

  • 很遗憾没有 w3wp.exe 进程。开发机器为xp sp3、iis5、vs2005sp1。
【解决方案3】:

此错误表明您试图在表中的列中插入大于该列最大长度的值。例如,您将列的最大长度指定为 20,而您尝试插入的字符串大于 20 个字符。

【讨论】:

    【解决方案4】:

    这两行:

    System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1297 
    System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +19 
    

    表明您的页面有一个带有 SELECT 语句的 SqlDataSource,并且正是该 SELECT 语句导致了错误。

    【讨论】:

    • 感谢您的信息。我希望明天在 sql 服务器上获得跟踪权限,这样我就可以尝试找出正在运行的查询。同时: SELECT 如何导致截断错误消息?我以为它只适用于数据库写入...
    • 仅仅因为它是附加到数据源的Select语句,并不意味着它是一个'SELECT * FROM Table'。它可能是一个存储过程,可以做很多其他事情(比如插入日志信息)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-19
    • 1970-01-01
    • 1970-01-01
    • 2013-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多