Truncated string error

  • Hello. I have a problem with one of my columns. While I was trying an asp page I had the following error:

    "String or binary data would be truncated."

    I used a form to insert a text to the database. The form successfully instered the text but at the same time it gave me this error.

    The datatype of the column that the text has been inserted is varchar(400) not null. The text is 75 chars long. I used a stored procedure and a Command object to process the form, with this:

    create procedure proc_name

    @column varchar(400)

    set nocount on

    ..

    objCmd.Parameters.Append objCmd.CreateParameter("@column", adVarChar, adParamInput, 400, requested_form)

    Do you have any idea why it did give me this error, while it successfully processed the data?

  • I don't recalll it being the case but could be a known issue needing a Service Pack install. If you have the latest and greatest service pack then use SQL Profiler on Statment started and stored proc started to see what is actually being passed to the server coul be a white space issue or some other simple problem you just aren't expecting. Coul also be another column if you pass multiple columns and oyu are looking in the wrong place.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • Is there any triggers on the table? Any other columns being updated?

    Chris Hedgate @ Apptus Technologies (http://www.apptus.se)

    http://www.sql.nu

  • You are telling the SQL database that the parameter you are sending in is 400 characters. I'm not sure exactly how strings are passed between ADO and SQL, but I think the problem may be that you are passing more than you need to. Can you set the length of the parameter being passed dynamically?

    objCmd.Parameters.Append objCmd.CreateParameter("@column", adVarChar, adParamInput, Len(requested_form), requested_form)

  • Shouldnt need to set the length dynamically, the reason you set the length in the parameter object is so that you can't call the proc with a string larger than the parameter declaration. Same goes for data typing, just lets you validate it server side to save you a trip.

    Andy

    http://qa.sqlservercentral.com/columnists/awarren/

  • Antares686:

    quote:


    Coul also be another column if you pass multiple columns and oyu are looking in the wrong place.


    No, only one column is effected in the script.

    chrhedga:

    quote:


    Is there any triggers on the table? Any other columns being updated?


    No, not even one.

  • Then I go back and say try profiler since you know how it occurrs and see what is going on under the hood of SQL with the calls. Otherwise try the latest SP for your server if not already installed to see if corrects.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply