locked
SqlCeParameter.Size limited to 255 characters for char types RRS feed

  • Question

  • SqlCeParameter.Size seems to be limited to 255 characters for char types.

     

    Eg.

    SqlCeParameter param = new SqlCeParameter();

    param.ParameterName = parameter_name;

    param.DbType = DbType.String;

    param.Size = 260;

     

    Now check the value of param.Size, it will be 255.

     

     In the past this problem was avoidable by setting the size to 0. However, this cause a problem if you are re-using the same command and simply changing the parameters value.

     

    Somewhere the system remembers the length of the first value and adjusts the max size to be limited to this length.

     

    Thus for the following values:

     

    "Test"

    "Testing"

     

    The second one will error with something like "@param: String truncation: max = 4, len = 7, value = 'testing' "

     

    Has anyone else come across this problem, or found a solution to it?

    Tuesday, July 10, 2007 2:08 PM

Answers

  •  

    This was a bug in 3.0 release of SQL Compact (called SQL Server Mobile then) in which maximum length for parameters of type nvarchar or nchar was taken wrongly as 255 (and binary and varbinary was taken as 510) . 

     

    It has been fixed now though. I think that the fix would be available in SQL Compact 3.5 Beta 1 (shipped with Visual Studio 'Orcas' Beta 1)

     

    Note that AnsiString DbType maps to varchar data type. This is not supported by SQL Compact. Only unicode data types nchar, nvarchar and ntext are supported.

    Thursday, July 19, 2007 10:27 AM

All replies

  • These forums don't seem to like re-posts, so how do I delete or move this post to the .Net Compact Framework forum?
    Thursday, July 12, 2007 11:01 AM
  •  

    This was a bug in 3.0 release of SQL Compact (called SQL Server Mobile then) in which maximum length for parameters of type nvarchar or nchar was taken wrongly as 255 (and binary and varbinary was taken as 510) . 

     

    It has been fixed now though. I think that the fix would be available in SQL Compact 3.5 Beta 1 (shipped with Visual Studio 'Orcas' Beta 1)

     

    Note that AnsiString DbType maps to varchar data type. This is not supported by SQL Compact. Only unicode data types nchar, nvarchar and ntext are supported.

    Thursday, July 19, 2007 10:27 AM