2

I did this project before with Entity Framework and Microsoft SQL Server 2008 without any problems. I had a table with two simple columns (ID and Name). I bound them to a DataGridView and I had no problem with Insert, Update or Delete.

Now I tried to do same thing but this time with two much complicated tables with auto-increment columns and foreign keys.

When I tried to save inserted information in database I had following exceptions:

An error occurred while updating the entries. See the inner exception for details.

INNER EXCEPTION: String or binary data would be truncated. The statement has been terminated.

After almost 10 times stop and re-run project error gone without I change anything. What was this error for? And why it gone without I change anythings?

I can not trust to Entity Framework if it want to throw random exceptions without reasons and stop to throw those exceptions after a while.

4
  • 4
    Usually this error occurs when the supplied data length is greater than the length specified in database field. Are you sure you didn't change anything in the database or the the inputs ? Commented Aug 4, 2012 at 13:31
  • Oh, yes your right, this error occurs when data length is greater than specified length for field in database. Thank you very much. Commented Aug 4, 2012 at 13:55
  • @Habib: Re-post that as an answer. :) Commented Aug 4, 2012 at 15:05
  • @Habib please write your comment as an answer. Commented Jun 18, 2019 at 8:06

2 Answers 2

1

Usually this error occurs when the supplied data length is greater than the length specified in database field.

Make sure that the database field length is enough to accommodate the input data.

Sign up to request clarification or add additional context in comments.

Comments

0

I would have commented this but i do not have enough reputation to comment. I was stuck on this same error.After seeing this answer what i did to quickly find where i am wrong is my using.

PM> update-database -force -Verbose

Verbose Tag have a look at the Sql Generated for the AutomaticMigrations.

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.