views:

141

answers:

4

hi,

I'm having troubles with an asp.net 2.0 application that I took over from other developers (meaning I don't really know much of the code). It is throwing an unhandled exception, but I cannot get any source info where exactly the exception occurs, and debug stepping through the source suddenly ends with the only option of showing disassembly code.

Is there anything else I can do in VS2005 or IIS to figure out where exactly the exception occurs?

Below is the output of the IIS error message (that usually shows source files, line numbers etc, but not in this case).

thanks.

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 
+1  A: 

The problem might be VS itself. In having such problems in the past, my problems have sometimes gone away with VS restart or reboot. Assuming that didn't help:

My guess is that VS is probably fine, and the data access layer (DAL) you're using is the problem. It seems to be trying to handle the error but not doing a very good job. I can't tell from the stack trace, but are you referencing another .NET library for you DAL, or using a 3rd party DAL? In the first case, you should be able to run that, put in break points, and then run your top-level code. You should be able to hit your breakpoints. If this is a 3rd party DAL, that won't work.

If you simply can not step through your DAL code, then you have to:

  1. Analyze the stack trace and try to piece together what's happening. You do have a good clue with the first line in the stack trace: something is trying to put data too big into a data structure too small. If this is a write process, then the thing-too-small is probably a field in the db -- compare the data you're working with compared to where it's going. If this is a read process, the thing-too-small is an intermediate sql UDF or procedure.
  2. Use the SQL Server Profiler to see what exactly is happening. (This assumes you're using SQL server of course.) If you haven't used that tool before, this is a great time to start. It will allow you to fix problems like this. Even when working with code with good error handling, this tool is great for production problems. With Profiler, you'll be able to see the sql action happening, and see where the error is happening.
Patrick Karcher
The DAL code is included in the project, and also set to compile in debug mode. while the debugger is still stepping through the code it actually goes into the DAL sources as well, just not when the exception occurs. I will start looking through the DAL code to see if breakpoints there will help, and also read up on server profiler. can this be run remotely also, as I will probably not be able to get direct access to the sql server machine.
Tom
Profiler can most definitely run remotely. You probably have it if sql server client tools are installed on your machine. The only potential problem is if you have DB-nazis who ask suspiciously "why do you need that? that's our job." or who won't give you permissions for a trace.
Patrick Karcher
"only" took me half a day to get the required permissions for tracing.. and it really helped so much. with the trace I quickly found out that a specific stored procedure was the cause (declared a variable field as a too small varchar, therefore the truncate error message).so thanks for the tip with the profiler -- now I'm wondering why I never used that before ;)
Tom
+1  A: 

This error indicates that you are trying to insert values in a column in a table greater than the max length of the column. For example you have specified max length for a column as 20 and the string you are trying to insert is greater than 20 characters.

Darin Dimitrov
+1  A: 

Well, that error message looks familiar. You are attempting to insert a value that is too big for the column in the database. It could either be a string or a number or something else. But you must be able to figure that out based on what you do when the error is triggered.

In order to debug what is happening you need to go to Debug -> Attach to process. And choose all w3wp.exe processes (to see them you might need to tick "show processes from all users" and "show processes in all sessions"). Furthermore you need to make sure that your website is built in the debug build configuration and not in release.

Hope it helps

klausbyskov
unfortunately there is no w3wp.exe process. development machine is xp sp3, iis5, vs2005sp1.
Tom
+1  A: 

These two lines:

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

indicate that your page has a SqlDataSource with a SELECT statement, and it is that SELECT statement that is causing the error.

Jason Berkan
thanks for the info. I will hopefully get trace permissions on the sql server tomorrow so I can try to figure out what query is being run. In the meantime: how can a SELECT result in the truncate error message? I thought it was only applicable to DB writes...
Tom
Just because it is the Select statement attached to the data source, does not mean it is a 'SELECT * FROM Table'. It could be a stored procedure that does a bunch of other stuff (like inserting logging information).
Jason Berkan