What does the SQL Server Error “String Data, Right Truncation” mean and how do I fix it?

前端 未结 4 1074
生来不讨喜
生来不讨喜 2021-01-01 11:36

We are doing some performance tests on our website and we are getting the following error a lot:

*** \'C:\\inetpub\\foo.plex\' log message at: 2008/10/07 13:         


        
相关标签:
4条回答
  • 2021-01-01 12:08

    This is a known issue of the mssql ODBC driver. According to the Microsoft blog post:

    The ColumnSize parameter of SQLBindParameter refers to the number of characters in the SQL type, while BufferLength is the number of bytes in the application's buffer. However, if the SQL data type is varchar(n) or char(n), the application binds the parameter as SQL_C_CHAR or SQL_C_VARCHAR, and the character encoding of the client is UTF-8, you may get a "String data, right truncation" error from the driver even if the value of ColumnSize is aligned with the size of the data type on the server. This error occurs since conversions between character encodings may change the length of the data. For example, a right apostrophe character (U+2019) is encoded in CP-1252 as the single byte 0x92, but in UTF-8 as the 3-byte sequence 0xe2 0x80 0x99.

    You can find the full article here.

    0 讨论(0)
  • 2021-01-01 12:10

    Either the parameter supplied for ZIP_CODE is larger (in length) than ZIP_CODEs column width or the parameter supplied for CITY is larger (in length) than CITYs column width.

    It would be interesting to know the values supplied for the two ? placeholders.

    0 讨论(0)
  • 2021-01-01 12:13

    I was facing the same issue. So, i created a stored Procedure and defined the size like @FromDate datetime, @ToDate datetime, @BL varchar(50)

    After defining the size in @BL varchar(50), i did not face any problem. Now it is working fine

    0 讨论(0)
  • 2021-01-01 12:24

    I got around the issue by using a convert on the "?", so my code looks like convert(char(50),?) and that got rid of the truncation error.

    0 讨论(0)
提交回复
热议问题