Mar 152011
 

I’m currently involved in a cutting edge project where we’re breaking  boundaries of MS CRM 2011 platform, sounds very cool (thrilling as well) so during next few months I’ll publish some of the findings/outcomes from that project. Today simple problem how many attributes can we have per entity. There is a lot of myths about that, 8K SQL limit  etc. Well the best way of checking that is test it how many attributes we can create but before test I’ll try to explain what’s happened to 8K limit per row in SQL 2008. In SQL Server 2008, this restriction is relaxed for tables that contain varchar, nvarchar, varbinary, sql_variant, or CLR user-defined type columns. The length of each one of these columns must still fall within the limit of 8,000 bytes; however, their combined widths can exceed the 8,060-byte limit. This applies to varchar, nvarchar, varbinary, sql_variant, or CLR user-defined type columns when they are created and modified, and also to when data is updated or inserted. So we’re clear we can have more then 8K in row (row overflow will help in theory), but there is a price for that this approach might affect performance because SQL Server still maintains a limit of 8 KB per page. That’s from SQL now metadata SDK.  Simple piece of code

var addedAttributes = new List();
for (int i = 0; i < length; i++)
{
StringAttributeMetadata stringAttribute = new StringAttributeMetadata
{
//Set base properties
SchemaName = "new_" + RandomString(30),
DisplayName = new Label("Sample String", 1033),
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
Description = new Label("String Attribute", 1033),
MaxLength = 100

};
addedAttributes.Add(stringAttribute);
}

foreach (AttributeMetadata anAttribute in addedAttributes)
{
try
{
CreateAttributeRequest createAttributeRequest = new CreateAttributeRequest
{
EntityName = enityname,
Attribute = anAttribute
};
_service.Execute(createAttributeRequest);
} catch(Exception e) {
HandleException(e)
throw;
}
}

and result


Exception: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: Attribute new_zqenmnkldrihmoefnisgtpayszqokf cannot be created because we have hit a maximum number of attributes allowed for an entity (1000).

so MS CRM has got limit 1000 attributes per entity. Now we clearly know what are the limits. Conclusion in theory you can create 1000 attributes per entity but you don;t want to do it performance will be affected and also from management perspective that’s not looking like sensible figure .

Share and Enjoy!
 Posted by at 2:27 am

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>