"The data was truncated" with SQL Server Compact Edition

Topics: Troubleshooting
Nov 18, 2011 at 10:19 AM

This is very strange. As far as I know I'm doing everything correctly - I have fields appropriately set as Unlimited(), and [StringLengthMax] on the model, but SQL CE throws this exception every time. It works perfectly in SQL Express on the other hand.

The issue was reported on my Audit module: http://orchardaudit.codeplex.com/workitem/1

This is my migration:

 

            // Audit table
            SchemaBuilder.CreateTable("AuditRecord", table => table
                .Column("Id", DbType.Int64, column => column.PrimaryKey().Identity())
                .Column("ContentItemId", DbType.Int32)
                .Column("ContentItemVersionId", DbType.Int32)
                .Column("UserLocationId", DbType.Int64)
                .Column("AuditCode", DbType.String, col => col.WithLength(31))
                .Column("AuditData", DbType.String, col => col.Unlimited())
                .Column<DateTime>("TimeInitiated")
                .Column<DateTime>("TimeCompleted", col => col.Nullable())
                .Column("SourceUrl", DbType.String, col=>col.WithLength(511))
            );
            // User location table
            SchemaBuilder.CreateTable("UserLocationRecord", table => table
                .Column<long>("Id", column => column.PrimaryKey().Identity())
                .Column<int>("UserId")
                .Column("IPv4Address", DbType.AnsiString, col => col.WithLength(15))
                .Column("IPv6Address", DbType.AnsiString, col => col.WithLength(39))
                .Column("CountryCode", DbType.String, col => col.WithLength(2).WithDefault("  "))
                .Column("BrowserDetails", DbType.String, col => col.Unlimited())
                .Column("HostDetails", DbType.String, col => col.Unlimited())
                .Column<DateTime>("FirstSeen")
                .Column<DateTime>("LastSeen")
                .Column<DateTime>("LastChecked")
            );

 

And these are my models:

    public class AuditRecord
    {

        public virtual long Id { get; set; }
        public virtual int? ContentItemId { get; set; }
        public virtual int? ContentItemVersionId { get; set; }
        public virtual long UserLocationId { get; set; }
        [StringLength(31)]
        public virtual string AuditCode { get; set; }
        [StringLengthMax]
        public virtual string AuditData { get; set; }

        public virtual DateTime TimeInitiated { get; set; }
        public virtual DateTime? TimeCompleted{ get; set; }
        [StringLength(511)]
        public virtual string SourceUrl { get; set; }

    }
    public class UserLocationRecord
    {

        public virtual long Id { get; set; }

        public virtual int? UserId { get; set; }

        [StringLength(15)]
        public virtual string IPv4Address { get; set; }

        [StringLength(39)]
        public virtual string IPv6Address { get; set; }

        [StringLengthMax]
        public virtual string BrowserDetails { get; set; }

        [StringLengthMax]
        public virtual string HostDetails { get; set; }

        [StringLength(2)]
        public virtual string CountryCode { get; set; }

        public virtual DateTime FirstSeen { get; set; }
        public virtual DateTime LastSeen { get; set; }
        public virtual DateTime LastChecked { get; set; }

    }

Islam_Ibrahim's workitem has a screenshot of the entity contents - nothing in there should be getting truncated. Does anyone know why this might be happening?

Thanks in advance

Nov 18, 2011 at 10:32 AM

Perhaps it could be that I'm using Int64 for the Id field? It's the only thing here that I haven't seen in core Orchard modules.