Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dave - 15 Jul 2007 04:26 GMT
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)

Signature

L. A. Jones

Eliyahu Goldin - 15 Jul 2007 08:52 GMT
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.

Signature

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

>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
[quoted text clipped - 77 lines]
>       at System.Web.UI.Page.ProcessRequestMain(Boolean
> includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Alexey Smirnov - 15 Jul 2007 08:56 GMT
> 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
[quoted text clipped - 73 lines]
> --
> 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).....

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.