Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How do I trace the origin of "String or binary data would be trunc

Reply
Thread Tools

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

 
 
=?Utf-8?B?RGF2ZQ==?=
Guest
Posts: n/a
 
      07-15-2007
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(SqlExc eption
exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnErro r(SqlException
exception, Boolean breakConnection)
at
System.Data.SqlClient.TdsParser.ThrowExceptionAndW arning(TdsParserStateObject
stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet
bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.FinishExecuteRead er(SqlDataReader
ds, RunBehavior runBehavior, String resetOptionsString)
at
System.Data.SqlClient.SqlCommand.RunExecuteReaderT ds(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.InternalExecuteNo nQuery(DbAsyncResult
result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at
System.Web.UI.WebControls.SqlDataSourceView.Execut eDbCommand(DbCommand
command, DataSourceOperation operation)
at
System.Web.UI.WebControls.SqlDataSourceView.Execut eInsert(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.OnCreat edUser(EventArgs
e)
at System.Web.UI.WebControls.CreateUserWizard.Attempt CreateUser()
at
System.Web.UI.WebControls.CreateUserWizard.OnNextB uttonClick(WizardNavigationEventArgs e)
at System.Web.UI.WebControls.Wizard.OnBubbleEvent(Obj ect source,
EventArgs e)
at System.Web.UI.WebControls.CreateUserWizard.OnBubbl eEvent(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(Command EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEven t(String
eventArgument)
at
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

--
L. A. Jones
 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      07-15-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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(SqlExc eption
> exception, Boolean breakConnection)
> at System.Data.SqlClient.SqlInternalConnection.OnErro r(SqlException
> exception, Boolean breakConnection)
> at
> System.Data.SqlClient.TdsParser.ThrowExceptionAndW arning(TdsParserStateObject
> stateObj)
> at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
> SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet
> bulkCopyHandler, TdsParserStateObject stateObj)
> at
> System.Data.SqlClient.SqlCommand.FinishExecuteRead er(SqlDataReader
> ds, RunBehavior runBehavior, String resetOptionsString)
> at
> System.Data.SqlClient.SqlCommand.RunExecuteReaderT ds(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.InternalExecuteNo nQuery(DbAsyncResult
> result, String methodName, Boolean sendToPipe)
> at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
> at
> System.Web.UI.WebControls.SqlDataSourceView.Execut eDbCommand(DbCommand
> command, DataSourceOperation operation)
> at
> System.Web.UI.WebControls.SqlDataSourceView.Execut eInsert(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.OnCreat edUser(EventArgs
> e)
> at System.Web.UI.WebControls.CreateUserWizard.Attempt CreateUser()
> at
> System.Web.UI.WebControls.CreateUserWizard.OnNextB uttonClick(WizardNavigationEventArgs
> e)
> at System.Web.UI.WebControls.Wizard.OnBubbleEvent(Obj ect source,
> EventArgs e)
> at System.Web.UI.WebControls.CreateUserWizard.OnBubbl eEvent(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(Command EventArgs e)
> at System.Web.UI.WebControls.Button.RaisePostBackEven t(String
> eventArgument)
> at
> System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
> eventArgument)
> at System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
> sourceControl, String eventArgument)
> at System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection
> postData)
> at System.Web.UI.Page.ProcessRequestMain(Boolean
> includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
>
> --
> L. A. Jones



 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      07-15-2007
On Jul 15, 5:26 am, Dave <(E-Mail Removed)> 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(SqlExc eption
> exception, Boolean breakConnection)
> at System.Data.SqlClient.SqlInternalConnection.OnErro r(SqlException
> exception, Boolean breakConnection)
> at
> System.Data.SqlClient.TdsParser.ThrowExceptionAndW arning(TdsParserStateObje*ct
> stateObj)
> at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
> SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet
> bulkCopyHandler, TdsParserStateObject stateObj)
> at System.Data.SqlClient.SqlCommand.FinishExecuteRead er(SqlDataReader
> ds, RunBehavior runBehavior, String resetOptionsString)
> at
> System.Data.SqlClient.SqlCommand.RunExecuteReaderT ds(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.InternalExecuteNo nQuery(DbAsyncResult
> result, String methodName, Boolean sendToPipe)
> at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
> at
> System.Web.UI.WebControls.SqlDataSourceView.Execut eDbCommand(DbCommand
> command, DataSourceOperation operation)
> at
> System.Web.UI.WebControls.SqlDataSourceView.Execut eInsert(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.OnCreat edUser(EventArgs
> e)
> at System.Web.UI.WebControls.CreateUserWizard.Attempt CreateUser()
> at
> System.Web.UI.WebControls.CreateUserWizard.OnNextB uttonClick(WizardNavigati*onEventArgs e)
> at System.Web.UI.WebControls.Wizard.OnBubbleEvent(Obj ect source,
> EventArgs e)
> at System.Web.UI.WebControls.CreateUserWizard.OnBubbl eEvent(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(Command EventArgs e)
> at System.Web.UI.WebControls.Button.RaisePostBackEven t(String
> eventArgument)
> at
> System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaiseP*ostBackEvent(String eventArgument)
> at System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
> sourceControl, String eventArgument)
> at System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection 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).....

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
floor(positive double) vs trunc(positive double) different Hicham Mouline C Programming 2 04-23-2010 06:50 PM
ios::trunc vs unlink aryan C++ 3 06-17-2008 07:15 AM
trunc in verilog arti VHDL 0 05-10-2006 02:36 PM
undefined reference to `trunc' Giulio C Programming 7 11-26-2004 01:06 AM



Advertisments