String or binary data would be truncated. The statement has been terminated. Asp.net - database

I am getting this error in spite of declaring every column datatype to max
This is my code I'm just logging my exceptions to the db
Desgin of my table,(I use ssms 2014)

Related

Type Conversion changes between Local PC and Server environment

I am taking some simple data from an SQL table, making a small transformation and converting it to Unicode. Then I output it into an Oracle CHAR(1 byte) field on an Oracle server.
This works without any error on my local PC. I then deploy to the server and it says that
"Column "A" cannot convert between unicode and non-unicode string data types".
After trying several things I threw my hands up in the air and just took out the data conversion to unicode and now it is broken and wont run on my PC.
BUT - it now works on the server and is all happy. I've searched and found that others have had this problem, but none seem to find the cause and just work around it it other ways.
Why can I not have my PC and my Server work the same? All tables and data connection are the SAME for both. No change other than execution location.
I got the same issue in my SSIS package and found no solution.
It was a simple data, not containing any unicode character, and it doesn't throw any exception if converting it using an SQL query or a .net code ... But it throws an exception in SSIS when using Data Conversion Transformation
Workarounds
I made a simple workaround to achieve this (you can use it if this error occurs again)
I replaced the Data Conversion Component with a Script Component
I marked the columns i want to convert as input
For each column i want to convert i created an output column of type DT_WSTR
In the Script for each column i used the following code: (assuming the input is inColumn and the output is outColumn)
If Not Row.inColumn_IsNull AndAlso _
Not String.IsNullOrEmpty(Row.inColumn) Then
Row.outColumn = Row.inColumn
Else
Row.outColumn_IsNull = True
End If
OR
If the source is an OLEDB Source you can use a casting function in the OLEDB source command
ex:
SELECT CAST([COLUMN] as NVARCHAR(255)) AS [COLUMN]
FROM ....

Not able to insert the rows which contain '#' special Character from CSV file to SQl database,using SSIS packages

When i am trying to import the CSV file into SQL tables using SSIS packages i was not able to insert the rows which contain '#' as special character.
It is throwing the following error:
'[DCNV - Unicode to NonUnicode [14]] Error: The "DCNV - Unicode to
NonUnicode.Outputs[Data Conversion Output].Columns[PrimaryAddr1]"
failed because truncation occurred, and the truncation row disposition
on "DCNV - Unicode to NonUnicode.Outputs[Data Conversion
Output].Columns[PrimaryAddr1]" specifies failure on truncation. A
truncation error occurred on the specified object of the specified
component.'
Please help me with this issue. How can i allow '#' special character to insert into Database tables. The column related to this issues are Customer Address(DT_WSTR)
Check out the source as well as the destination data types to make sure you are specifying them correctly - Jet has probably guessed wrong - it only looks at the first few rows to guess what datatype your data is.
Also notice there error is actually complaining about Unicode to NonUnicode - make sure the source/destination lengths are correct and depict your data.

string or binary data would be truncated - but don't know parameter values

The company program prints out the string or binary data would be truncated error to an error table when trying to insert into a specific table. I do realize from other posts that the cause of this is the current table structure. There are one or more fields that are too short, but unfortunately I do not have access to the values of the actual query. Instead, it dumps them as #parametername1, #parametername2, etc. from the stacktrace.
Is there any way I can see from some kind of monitoring tool in SQL Server 2012 what parameter and value failed? I mean, the SQL Server has returned the error, so supposedly I can log it if I repeat the error?
You can setup a trace in SQL Profiler. For the statement, it will give you list of columns and matching values being inserted.

Entity Framework String would be truncated Error

I have a flat-file SQL Server database. I'm trying to insert info into the table but I keep getting "String or binary data would be truncated" errors every time I run it. ALL of my text fields are nvarchar(max), but it still throws the error and I can look at the data, and nothing is over 8192 characters. I don't think anything is over 256, to be honest.
Any ideas?
I'm using Visual Studio 11 and Entity Framework 4 if that matters.
SQL Server 2019 should produce a different error message that contains the table and the column that causes the conflict
Error message ID 8152 has been replaced with error 2628 to now include the column and string value that would be truncated.
“String or binary string would be truncated in table , column . Truncated value: ”
See also https://blogs.msdn.microsoft.com/sql_server_team/string-or-binary-data-would-be-truncated-replacing-the-infamous-error-8152/
Note that for now, even in SQL Server 2019 CTP 2.0 the same trace flag 460 needs to be enabled. In a future SQL Server 2019 release, message 2628 will replace message 8152 by default.

What happens to ignored rows when Ignore failure is selected in SSIS?

There are 3 components in the data flow: an OLE DB Source, Data Conversion transformation and a Flat File Destination. If I selected the Ignore failure option in the Data conversion transformation and some rows get ignored in that data conversion level then would those ignored rows move towards target? Or where can I get those ignored rows? Are those going to available in the log file?
What will happen to erroneous rows when I select Fail component as option?
The standard behavior when you select Ignore failure seems to be to ignore the offending values, not the rows that contain them. I just did a quick test (SQL Server 2008 R2) and values are imported with NULL instead of the offending values.
You can find a very helpful page with more information on error handling in SSIS Data Flow tasks here. An overview from that page of the relevant error handling options and what they mean:
Fail Component:
The Data Flow task fails when an error or a truncation occurs. Failure is the default option for an error and a truncation.
Ignore Failure:
The error or the truncation is ignored and the data row is directed to the output of the transformation or source.
Redirect Row:
The error or the truncation data row is directed to the error output of the source, transformation, or destination.
As per SQL 2014, if you set Truncate Row Disposition to "RD_IgnoreFailure" the column data will be truncated to the specified length and inserted into destination. For example, if the column size is 50 and the data length is 70, the first 50 characters will be inserted to the destination.
why did you tag sql server 2000 and 2008? Its different on each version, even from 2005 to 2008 it changes. On 2008 you can drag the failed rows to another oledbdestination for example and insert them on a failed-log-table.

Resources