Reputation: 2699
im having this problem in Java using Log4j to logg to a SQL Server Database. It is usually thrown when you try to insert data into a column exceeding its size or limit, but unfortunately this is not my case. It logs perfect for some seconds and then... Boom! (Failed to execute SQL - Data Truncation).
I send Strings containing IP Adresses:
log.debug("Connecting to server... 100.0.0.1");
I found this:
An expression may inadvertently cause data to be truncated. Truncation can occur under the following circumstances:
Strings. For example, translating string data with a DT_WSTR data type to the same length string, measured in characters, with a DT_STR data type causes data loss if the original string contains double-byte characters.
Significant digits. For example, casting an integer from a DT_I4 data type to a DT_I2 data type or an unsigned integer to a signed integer. Insignificant digits. For example, casting a real number from a DT_R8 to a DT_R4 or an integer from a DT_I4 data type to a DT_R4 data type.
http://msdn.microsoft.com/en-us/library/ms137867.aspx
Maybe someone already know how to solve this so i asked.
Thanks for reading.
Upvotes: 1
Views: 254
Reputation: 2699
I Solved this issue. i was wrong about:
It is usually thrown when you try to insert data into a column exceeding its size or limit, but unfortunately this is not my case.
Because yes, it was my case. I had a column with a SmallInt type truncating because i was inserting very big numbers so i switched to just INT and problem solved. Also, if it happening with Strings you can try changing VARCHAR to NVARCHAR, since varchar just takes ASCII and nvarchar can take UNICODE too.
Upvotes: 1