System. Data. SqlClient. SqlException: truncates string or binary Data.

Source: Internet
Author: User

Problem:

"System. Data. SqlClient. SqlException" type unprocessed exceptions occur in System. Data. dll. Other information: truncates string or binary data.

This is a problem encountered when setting the basic data of the data room charging system.


In the Code UI Layer, Try ...... Catch caught exceptions, such:



But if you haven't encountered this problem, you can't solve it simply by looking at it. So I Try ...... Comment out the Catch and find the detailed information for throwing an exception:


Solution:

First, it is "System. data. sqlClient. sqlException ", you don't need to think about it. It must be a database problem. After debugging, we found the field value basicDataBLL inserted into the database. the SetDate value is "2014/6/17 Tuesday ":

However, the data type I set for this field in the database is varchar (10), which is far less than the space occupied by "2014/6/17 Tuesday! Therefore, the capacity of the data type was decisively increased, and varchar (10) programming varchar (20) was solved.

Summary:

Another test was conducted to reduce the storage capacity of other string, text, and other types of fields in the database. This problem also occurs, and a conclusion is obtained:

The cause of this problem isThe data type of a field in the database is insufficient to store the data length of the value to be inserted into the field.When the problem occurs, add the length of the Data Type of the corresponding field.


Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.