I'm having a very strange issue. I have windows service which is failing because of a SqlException: "String or binary data would be truncated." for an INSERT statement.
Now this is a fairly basic error to solve but it is not the true error. If I do a trace and run the query straight on the database - there is NO error. All of the data in WAY shorter than the restrictions on the database.
I eventually took out some of this required columns from the query hoping to generate a different error: "Cannot insert the value NULL into column 'Type'"
I don't however get this error! I am still getting "String or binary data would be truncated."
I DO get this error if I run the query from the trace straight on the DB.
Does anyone have any ideas on what could be happening here? Thanks!
Edit to add Here's the query that is supposed to give me the cannot insert value error. The other query is the same but with more parameters:
declare @p4 int
set @p4=60029550
exec sp_executesql N'EXECUTE ssl_GetTTDVersionCallSeq 1, @TTDVersionIDVal OUTPUT
INSERT INTO TTDVersion(Task,ID) VALUES (@P0,@TTDVersionIDVal)',N'@P0 int,@TTDVersionIDVal int output',@P0=200003762,@TTDVersionIDVal=@p4 output
select @p4
Found the cause of this error. It was not at all in the query posted above. There was a trigger on the table which set the LastUpdatedBy column.
Most of the users have a 4 char user name but the user that the service was being run as didn't. The column limit was 4.
Avoid this issue:
What I should of tried earlier: