How do I trace the origin of "String or binary data would be trunc

Discussion in 'ASP .Net' started by =?Utf-8?B?RGF2ZQ==?=, Jul 15, 2007.

  1. I get this error: "String or binary data would be truncated" when I try to
    insert data in the database. But the stack trace gives no clue as to what is
    the offending data column. How can see the offending column?


    Stack Trace
    System.Data.SqlClient.SqlException was unhandled by user code
    Message="String or binary data would be truncated.\r\nThe statement has
    been terminated."
    Source=".Net SqlClient Data Provider"
    ErrorCode=-2146232060
    Class=16
    LineNumber=1
    Number=8152
    Procedure=""
    Server="jones\\sqlexpress"
    State=2
    StackTrace:
    at System.Data.SqlClient.SqlConnection.OnError(SqlException
    exception, Boolean breakConnection)
    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
    exception, Boolean breakConnection)
    at
    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
    stateObj)
    at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
    SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet
    bulkCopyHandler, TdsParserStateObject stateObj)
    at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader
    ds, RunBehavior runBehavior, String resetOptionsString)
    at
    System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior
    cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
    cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method,
    DbAsyncResult result)
    at
    System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult
    result, String methodName, Boolean sendToPipe)
    at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
    at
    System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand
    command, DataSourceOperation operation)
    at
    System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values)
    at System.Web.UI.WebControls.SqlDataSourceView.Insert(IDictionary
    values)
    at System.Web.UI.WebControls.SqlDataSource.Insert()
    at CreateUser.CreateUserWizard1_CreatedUser(Object sender, EventArgs
    e) in c:\Documents and Settings\Llewelyn Jones\My Documents\Visual Studio
    2005\webRetail\CreateUser.aspx.cs:line 33
    at System.Web.UI.WebControls.CreateUserWizard.OnCreatedUser(EventArgs
    e)
    at System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser()
    at
    System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs e)
    at System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source,
    EventArgs e)
    at System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object
    source, EventArgs e)
    at
    System.Web.UI.WebControls.Wizard.WizardChildTable.OnBubbleEvent(Object
    source, EventArgs args)
    at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
    args)
    at System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e)
    at System.Web.UI.WebControls.Button.RaisePostBackEvent(String
    eventArgument)
    at
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
    at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    sourceControl, String eventArgument)
    at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    at System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

    --
    L. A. Jones
    =?Utf-8?B?RGF2ZQ==?=, Jul 15, 2007
    #1
    1. Advertising

  2. The error is reported by the sql server whereas the stack trace comes from
    your app. That's why you don't see in the stack any additional info. Catch
    the actual query sent to the server either with the database tracer or with
    a breakpoint in the application and see what column has a too long value.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Dave" <> wrote in message
    news:...
    >I get this error: "String or binary data would be truncated" when I try to
    > insert data in the database. But the stack trace gives no clue as to what
    > is
    > the offending data column. How can see the offending column?
    >
    >
    > Stack Trace
    > System.Data.SqlClient.SqlException was unhandled by user code
    > Message="String or binary data would be truncated.\r\nThe statement has
    > been terminated."
    > Source=".Net SqlClient Data Provider"
    > ErrorCode=-2146232060
    > Class=16
    > LineNumber=1
    > Number=8152
    > Procedure=""
    > Server="jones\\sqlexpress"
    > State=2
    > StackTrace:
    > at System.Data.SqlClient.SqlConnection.OnError(SqlException
    > exception, Boolean breakConnection)
    > at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
    > exception, Boolean breakConnection)
    > at
    > System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
    > stateObj)
    > at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
    > SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet
    > bulkCopyHandler, TdsParserStateObject stateObj)
    > at
    > System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader
    > ds, RunBehavior runBehavior, String resetOptionsString)
    > at
    > System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior
    > cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
    > at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
    > cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method,
    > DbAsyncResult result)
    > at
    > System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult
    > result, String methodName, Boolean sendToPipe)
    > at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
    > at
    > System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand
    > command, DataSourceOperation operation)
    > at
    > System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary
    > values)
    > at System.Web.UI.WebControls.SqlDataSourceView.Insert(IDictionary
    > values)
    > at System.Web.UI.WebControls.SqlDataSource.Insert()
    > at CreateUser.CreateUserWizard1_CreatedUser(Object sender, EventArgs
    > e) in c:\Documents and Settings\Llewelyn Jones\My Documents\Visual Studio
    > 2005\webRetail\CreateUser.aspx.cs:line 33
    > at
    > System.Web.UI.WebControls.CreateUserWizard.OnCreatedUser(EventArgs
    > e)
    > at System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser()
    > at
    > System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs
    > e)
    > at System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source,
    > EventArgs e)
    > at System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object
    > source, EventArgs e)
    > at
    > System.Web.UI.WebControls.Wizard.WizardChildTable.OnBubbleEvent(Object
    > source, EventArgs args)
    > at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
    > args)
    > at System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e)
    > at System.Web.UI.WebControls.Button.RaisePostBackEvent(String
    > eventArgument)
    > at
    > System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
    > eventArgument)
    > at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    > sourceControl, String eventArgument)
    > at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection
    > postData)
    > at System.Web.UI.Page.ProcessRequestMain(Boolean
    > includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    >
    > --
    > L. A. Jones
    Eliyahu Goldin, Jul 15, 2007
    #2
    1. Advertising

  3. On Jul 15, 5:26 am, Dave <> wrote:
    > I get this error: "String or binary data would be truncated" when I try to
    > insert data in the database. But the stack trace gives no clue as to what is
    > the offending data column. How can see the offending column?
    >
    > Stack Trace
    > System.Data.SqlClient.SqlException was unhandled by user code
    > Message="String or binary data would be truncated.\r\nThe statement has
    > been terminated."
    > Source=".Net SqlClient Data Provider"
    > ErrorCode=-2146232060
    > Class=16
    > LineNumber=1
    > Number=8152
    > Procedure=""
    > Server="jones\\sqlexpress"
    > State=2
    > StackTrace:
    > at System.Data.SqlClient.SqlConnection.OnError(SqlException
    > exception, Boolean breakConnection)
    > at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
    > exception, Boolean breakConnection)
    > at
    > System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObje­ct
    > stateObj)
    > at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
    > SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet
    > bulkCopyHandler, TdsParserStateObject stateObj)
    > at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader
    > ds, RunBehavior runBehavior, String resetOptionsString)
    > at
    > System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior
    > cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
    > at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
    > cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method,
    > DbAsyncResult result)
    > at
    > System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult
    > result, String methodName, Boolean sendToPipe)
    > at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
    > at
    > System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand
    > command, DataSourceOperation operation)
    > at
    > System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values)
    > at System.Web.UI.WebControls.SqlDataSourceView.Insert(IDictionary
    > values)
    > at System.Web.UI.WebControls.SqlDataSource.Insert()
    > at CreateUser.CreateUserWizard1_CreatedUser(Object sender, EventArgs
    > e) in c:\Documents and Settings\Llewelyn Jones\My Documents\Visual Studio
    > 2005\webRetail\CreateUser.aspx.cs:line 33
    > at System.Web.UI.WebControls.CreateUserWizard.OnCreatedUser(EventArgs
    > e)
    > at System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser()
    > at
    > System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigati­onEventArgs e)
    > at System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source,
    > EventArgs e)
    > at System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object
    > source, EventArgs e)
    > at
    > System.Web.UI.WebControls.Wizard.WizardChildTable.OnBubbleEvent(Object
    > source, EventArgs args)
    > at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
    > args)
    > at System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e)
    > at System.Web.UI.WebControls.Button.RaisePostBackEvent(String
    > eventArgument)
    > at
    > System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaiseP­ostBackEvent(String eventArgument)
    > at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    > sourceControl, String eventArgument)
    > at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    > at System.Web.UI.Page.ProcessRequestMain(Boolean
    > includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    >
    > --
    > L. A. Jones


    The Insert statement of the SqlDataSource was failed, because some of
    your columns could be bigger than the defined size, and db doesn't
    allow you to insert data larger than a column definition. You should
    either 1) perform validation to ensure that the form input parameters
    are correct or 2) conform the data to the required internal db
    structure.

    1) Use MaxLength property, or a RegularExpressionValidator

    <asp:TextBox MaxLength="X"

    2) Use Left function

    INSERT .... Left(@parameter,X).....
    Alexey Smirnov, Jul 15, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. arti

    trunc in verilog

    arti, May 10, 2006, in forum: VHDL
    Replies:
    0
    Views:
    576
  2. Giulio

    undefined reference to `trunc'

    Giulio, Nov 24, 2004, in forum: C Programming
    Replies:
    7
    Views:
    3,230
    Dave Vandervies
    Nov 26, 2004
  3. Guest
    Replies:
    5
    Views:
    424
    Scott David Daniels
    Mar 30, 2007
  4. aryan

    ios::trunc vs unlink

    aryan, Jun 16, 2008, in forum: C++
    Replies:
    3
    Views:
    760
    James Kanze
    Jun 17, 2008
  5. Hicham Mouline
    Replies:
    2
    Views:
    768
    Keith Thompson
    Apr 23, 2010
Loading...

Share This Page