Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Daniel Rogers 139 posts 717 karma points
    Oct 08, 2024 @ 08:35
    Daniel Rogers
    0

    Umrabraco 14 'String or binary data would be truncated in table 'Development-u14.dbo.umbracoPropertyData'

    I have created a custom property and it stares a json object.

    It worked initially when the propertyEditorSchemaAlias was a Umbraco.Plain.Json

    But now trying to add the DataValueEditor and validation as per the my suggestions example but this is for a string.

    Cant find the documentation to support other value types.

    Code is as below

    namespace Umbraco.Docs.PropertyEditors;

    [DataEditor("IBD.Additional.Classes", ValueEditorIsReusable = true)] public class IBDAdditionalClassesDataEditor : DataEditor { public IBDAdditionalClassesDataEditor(IDataValueEditorFactory dataValueEditorFactory) : base(dataValueEditorFactory) { }

    protected override IDataValueEditor CreateValueEditor()
        => DataValueEditorFactory.Create<IBDAdditionalClassesDataValueEditor>(Attribute!);
    

    }

    public class IBDAdditionalClassesDataValueEditor : DataValueEditor
    {
        public IBDAdditionalClassesDataValueEditor(
            IShortStringHelper shortStringHelper,
            IJsonSerializer jsonSerializer,
            IIOHelper ioHelper,
            DataEditorAttribute attribute)
            : base(shortStringHelper, jsonSerializer, ioHelper, attribute)
            => Validators.Add(new IBDAdditionalClassesValueValidator());
    }
    
    public class IBDAdditionalClassesValueValidator : IValueValidator
    {
        public IEnumerable<ValidationResult> Validate(object? value, string? valueType, object? dataTypeConfiguration)
        {
            return (value is System.Text.Json.JsonDocument
                && dataTypeConfiguration is not Dictionary<string, object?> dataTypeConfigurationValues)
                ? []
                : [new ValidationResult($"Not Valid value")];
        }
    }
    

    Not sure if the validation is correct?

    Error that is logged is this when saving and publishing the document.

    {"@t":"2024-10-07T14:34:07.7927704Z","@mt":"Exception ({InstanceId}).","@l":"Error","@x":"Microsoft.Data.SqlClient.SqlException (0x80131904): String or binary data would be truncated in table 'Development-u14.dbo.umbracoPropertyData', column 'varcharValue'. Truncated value: '[\r\n  {\r\n    \"key\": \"d4a313e4-29db-43c8-b00f-d6e0bf1d28c1\",\r\n    \"heading\": \"Pod Styles\",\r\n    \"type\"'.\r\nThe statement has been terminated.\r\n   at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)\r\n   at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)\r\n   at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)\r\n   at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)\r\n   at Microsoft.Data.SqlClient.SqlDataReader.TryConsumeMetaData()\r\n   at Microsoft.Data.SqlClient.SqlDataReader.get_MetaData()\r\n   at Microsoft.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)\r\n   at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean isAsync, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)\r\n   at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String method)\r\n   at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)\r\n   at Microsoft.Data.SqlClient.SqlCommand.ExecuteScalar()\r\n   at StackExchange.Profiling.Data.ProfiledDbCommand.ExecuteScalar() in C:\\projects\\dotnet\\src\\MiniProfiler.Shared\\Data\\ProfiledDbCommand.cs:line 315\r\n   at Umbraco.Cms.Infrastructure.Persistence.FaultHandling.FaultHandlingDbCommand.<ExecuteScalar>b__36_0()\r\n   at Umbraco.Cms.Infrastructure.Persistence.FaultHandling.RetryPolicy.ExecuteAction[TResult](Func`1 func)\r\n   at Umbraco.Cms.Infrastructure.Persistence.FaultHandling.FaultHandlingDbCommand.ExecuteScalar()\r\n   at NPoco.Database.<>c__DisplayClass297_0.<ExecuteScalarHelper>b__0()\r\n   at NPoco.Database.ExecuteScalarHelper(DbCommand cmd)\r\n   at NPoco.Database.NPoco.IDatabaseHelpers.ExecuteScalarHelper(DbCommand cmd)\r\n   at NPoco.DatabaseTypes.SqlServerDatabaseType.ExecuteInsert[T](Database db, DbCommand cmd, String primaryKeyName, Boolean useOutputClause, T poco, Object[] args)\r\n   at NPoco.Database.InsertAsyncImp[T](PocoData pocoData, String tableName, String primaryKeyName, Boolean autoIncrement, T poco, Boolean sync)\r\n   at NPoco.AsyncHelper.RunSync[T](Task`1 task)\r\n   at NPoco.Database.Insert[T](String tableName, String primaryKeyName, Boolean autoIncrement, T poco)\r\n   at NPoco.Database.Insert[T](T poco)\r\n   at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.ContentRepositoryBase`3.ReplacePropertyValues(TEntity entity, Int32 versionId, Int32 publishedVersionId, Boolean& edited, HashSet`1& editedCultures)\r\n   at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.DocumentRepository.PersistUpdatedItem(IContent entity)\r\n   at Umbraco.Cms.Core.Cache.DefaultRepositoryCachePolicy`2.Update(TEntity entity, Action`1 persistUpdated)\r\nClientConnectionId:2680b7c2-0a21-4af7-8681-79acab983656\r\nError Number:2628,State:1,Class:16","@tr":"218c5d12d37bb4ad26e34a029b534e72","@sp":"f2e8e742b76d6b77","InstanceId":"2a8165bc","SourceContext":"Umbraco.Cms.Infrastructure.Persistence.UmbracoDatabase","ActionId":"a170bfd8-0bff-40af-be92-a1a65928475b","ActionName":"Umbraco.Cms.Api.Management.Controllers.Document.UpdateDocumentController.Update (Umbraco.Cms.Api.Management)","RequestId":"40000023-000d-f600-b63f-84710c7967bb","RequestPath":"/umbraco/management/api/v1/document/7f14b779-20a6-4b0a-8b32-cbc4032c319e","ProcessId":25944,"ProcessName":"iisexpress","ThreadId":83,"ApplicationId":"22a156123ee2f165741f6e63316cf003dd6ac00f","MachineName":"IBD-MSI-DESKTOP","Log4NetLevel":"ERROR","HttpRequestId":"2ddc0684-fd6d-43a6-abb2-cae9fb25a1c6","HttpRequestNumber":4,"HttpSessionId":"7f001777-e3f9-10e1-afa1-f7ac956b8b9e"}
    {"@t":"2024-10-07T14:34:07.9135880Z","@mt":"Content save operation failed","@l":"Error","@x":"Microsoft.Data.SqlClient.SqlException (0x80131904): String or binary data would be truncated in table 'Development-u14.dbo.umbracoPropertyData', column 'varcharValue'. Truncated value: '[\r\n  {\r\n    \"key\": \"d4a313e4-29db-43c8-b00f-d6e0bf1d28c1\",\r\n    \"heading\": \"Pod Styles\",\r\n    \"type\"'.\r\nThe statement has been terminated.\r\n   at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)\r\n   at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)\r\n   at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)\r\n   at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)\r\n   at Microsoft.Data.SqlClient.SqlDataReader.TryConsumeMetaData()\r\n   at Microsoft.Data.SqlClient.SqlDataReader.get_MetaData()\r\n   at Microsoft.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)\r\n   at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean isAsync, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)\r\n   at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String method)\r\n   at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)\r\n   at Microsoft.Data.SqlClient.SqlCommand.ExecuteScalar()\r\n   at StackExchange.Profiling.Data.ProfiledDbCommand.ExecuteScalar() in C:\\projects\\dotnet\\src\\MiniProfiler.Shared\\Data\\ProfiledDbCommand.cs:line 315\r\n   at Umbraco.Cms.Infrastructure.Persistence.FaultHandling.FaultHandlingDbCommand.<ExecuteScalar>b__36_0()\r\n   at Umbraco.Cms.Infrastructure.Persistence.FaultHandling.RetryPolicy.ExecuteAction[TResult](Func`1 func)\r\n   at Umbraco.Cms.Infrastructure.Persistence.FaultHandling.FaultHandlingDbCommand.ExecuteScalar()\r\n   at NPoco.Database.<>c__DisplayClass297_0.<ExecuteScalarHelper>b__0()\r\n   at NPoco.Database.ExecuteScalarHelper(DbCommand cmd)\r\n   at NPoco.Database.NPoco.IDatabaseHelpers.ExecuteScalarHelper(DbCommand cmd)\r\n   at NPoco.DatabaseTypes.SqlServerDatabaseType.ExecuteInsert[T](Database db, DbCommand cmd, String primaryKeyName, Boolean useOutputClause, T poco, Object[] args)\r\n   at NPoco.Database.InsertAsyncImp[T](PocoData pocoData, String tableName, String primaryKeyName, Boolean autoIncrement, T poco, Boolean sync)\r\n   at NPoco.AsyncHelper.RunSync[T](Task`1 task)\r\n   at NPoco.Database.Insert[T](String tableName, String primaryKeyName, Boolean autoIncrement, T poco)\r\n   at NPoco.Database.Insert[T](T poco)\r\n   at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.ContentRepositoryBase`3.ReplacePropertyValues(TEntity entity, Int32 versionId, Int32 publishedVersionId, Boolean& edited, HashSet`1& editedCultures)\r\n   at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.DocumentRepository.PersistUpdatedItem(IContent entity)\r\n   at Umbraco.Cms.Core.Cache.DefaultRepositoryCachePolicy`2.Update(TEntity entity, Action`1 persistUpdated)\r\n   at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.EntityRepositoryBase`2.Save(TEntity entity)\r\n   at Umbraco.Cms.Core.Services.ContentService.Save(IContent content, Nullable`1 userId, ContentScheduleCollection contentSchedule)\r\n   at Umbraco.Cms.Core.Services.ContentEditingService.Save(IContent content, Guid userKey)\r\nClientConnectionId:2680b7c2-0a21-4af7-8681-79acab983656\r\nError Number:2628,State:1,Class:16","@tr":"218c5d12d37bb4ad26e34a029b534e72","@sp":"f2e8e742b76d6b77","SourceContext":"Umbraco.Cms.Core.Services.ContentEditingService","ActionId":"a170bfd8-0bff-40af-be92-a1a65928475b","ActionName":"Umbraco.Cms.Api.Management.Controllers.Document.UpdateDocumentController.Update (Umbraco.Cms.Api.Management)","RequestId":"40000023-000d-f600-b63f-84710c7967bb","RequestPath":"/umbraco/management/api/v1/document/7f14b779-20a6-4b0a-8b32-cbc4032c319e","ProcessId":25944,"ProcessName":"iisexpress","ThreadId":83,"ApplicationId":"22a156123ee2f165741f6e63316cf003dd6ac00f","MachineName":"IBD-MSI-DESKTOP","Log4NetLevel":"ERROR","HttpRequestId":"2ddc0684-fd6d-43a6-abb2-cae9fb25a1c6","HttpRequestNumber":4,"HttpSessionId":"7f001777-e3f9-10e1-afa1-f7ac956b8b9e"}
    

    I think some how I need the IBD.Additional.Classes to be stored in the textValue column for the table rather than the varCharString column.

    or make IBD.Additional.Classes the equivalent of Umbraco.Plain.JSon

Please Sign in or register to post replies

Write your reply to:

Draft