How to ignore System.Data.SqlClient.SqlException: String or binary data will be truncated. an exception

I know that my data is too large and that is why I get an exception. However, this is more like a warning. Is there a property in SQLCommand that I can set to be just a warning and to insert truncated data anyway? An attempt to eliminate all possible questions that can be quickly answered. I cannot resize a column in SQLDatabase. I do not have permission to do so. I would like to avoid going to each line and say if length> x takes a substring. I just want this to be ignored at the command level.

+3
source share
2 answers

You can execute SET ANSI_WARNINGS OFFto suppress this message. Or you can use the functions LEFT|| RIGHTto crop data and pass the maximum number of characters for a column.

+6
source

You can turn off ANSI warnings and get around this, but that means chaining commands to turn off and on or use stored procedures to do this. I have not studied all the parameters of the database, but I believe that this can only be done at the package level. Even if it can be done for the entire database, I don’t think it can be configured for a specific table. And even if this can be done for the entire database, this is a bad idea. It’s best to use a setting where you don’t care about truncation.

-, - , . , , ?

0

All Articles