none
why can not update string type with length 256? RRS feed

  • Question

  • Error is String or binary data would be truncated.
    The statement has been terminated.
    Why can not update string type with length 256?
     CryptographyManager defaultCrypto = EnterpriseLibraryContainer.Current.GetInstance<CryptographyManager>();
        PasswordObject pwd = new PasswordObject(New_Password.Text.Trim().ToUpper());
        byte[] serializedObject = SerializationUtility.ToBytes(pwd);
        byte[] encrypted = defaultCrypto.EncryptSymmetric("RijndaelManaged", serializedObject);
    
        string updateString = "Update UserProfile set Password = '" + Convert.ToBase64String(encrypted) + "', Last_PasswordChange_Date = '" + DateTime.Now.ToString("yyyy-MM-dd 00:00:00") + "' where upper(rtrim(UserID)) = upper(rtrim('" + UserID + "'))";
        string error_test = Util.ExecuteDatabase(updateString);
    


    Hello
    Thursday, June 23, 2011 3:34 AM

Answers

  • Most probably the type of the column in the database is varchar(255) so it simply cannot hold 256 characters.

     

    You are aware of the fact that the way you wrote the statement it's 1) susceptible to SQL injection attacks and 2) not going to use any index even if you happened to have one on the UserProfile table?


    ----------------------------------
    http://jendaperl.blogspot.com
    A Perl developer in the world of C#
    • Marked as answer by 沈世鈞 Tuesday, June 28, 2011 1:11 AM
    Friday, June 24, 2011 12:24 PM

All replies

  • Most probably the type of the column in the database is varchar(255) so it simply cannot hold 256 characters.

     

    You are aware of the fact that the way you wrote the statement it's 1) susceptible to SQL injection attacks and 2) not going to use any index even if you happened to have one on the UserProfile table?


    ----------------------------------
    http://jendaperl.blogspot.com
    A Perl developer in the world of C#
    • Marked as answer by 沈世鈞 Tuesday, June 28, 2011 1:11 AM
    Friday, June 24, 2011 12:24 PM
  • I have already set nvarchar(max) and debug to confirm the length is exact 256
    Hello
    Monday, June 27, 2011 1:51 AM
  • Set where? In the database? Really? Script out the table and show us the sql!

    If the database column really is nvarchar(max) and you are really accessing the database you think you are accessing then there must be a trigger on that table trying to copy the value into some other table that still has nvarchar(255).  


    ----------------------------------
    http://jendaperl.blogspot.com
    A Perl developer in the world of C#
    Monday, June 27, 2011 5:40 PM
  • solved now due to trigger's log


    Hello
    Tuesday, June 28, 2011 1:11 AM