Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Error adding custom entity: auto SQL tries to add duplicate field

Posted on by Microsoft Employee

A baffling error... When adding a custom entity, I get a SQL error pop up, and this contained in the log file:

 

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.Data.SqlClient.SqlException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #42040FB6Detail: 

<OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts">
<ErrorCode>-2147220970</ErrorCode>
<ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic" />
<Message>System.Data.SqlClient.SqlException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #42040FB6</Message>
<Timestamp>2015-07-23T15:47:19.3617506Z</Timestamp>
<InnerFault i:nil="true" />
<TraceText i:nil="true" />
</OrganizationServiceFault>

Our MS Dynamics CRM 2015 is hosted on a server, which I don't have full access to. However, the administrator of the server sent me this from the log, which gives more detail (see below). Note the bits highlighted in red. It seems clear to me that the SQL error is happening because when creating the entity table, Dynamics has created a SQL script that includes the same field name twice: once as uniqueidentifier and once as nvarchar.

I'm really baffled as to why this has happened. I was able to add entities yesterday. This error has just occurred and, as far as I know, with no changes to the server setup since yesterday.

Has anybody seen this before?


With thanks
James

[2015-07-23 13:49:25.532] Process: w3wp |Organization:8c07a7e5-8a21-e511-80bc-0050568c61d1 |Thread:   30 |Category: Platform.Metadata |User: 00000000-0000-0000-0000-000000000000 |Level: Error |ReqId: a03e2e2e-5ce9-4920-83c3-bc6edfc70ea1 | SqlHelper.ExecuteNonQuery  ilOffset = 0x29

>Exception when executing non-query: CREATE TABLE dbo.[fcp_factfindBase] ([fcp_factfindId] uniqueidentifier   NOT NULL  ,

                [CreatedOn] datetime   NULL  ,

                [CreatedBy] uniqueidentifier   NULL  ,

                [ModifiedOn] datetime   NULL  ,

                [ModifiedBy] uniqueidentifier   NULL  ,

                [CreatedOnBehalfBy] uniqueidentifier   NULL  ,

                [ModifiedOnBehalfBy] uniqueidentifier   NULL  ,

                [OwnerId] uniqueidentifier   NOT NULL  ,

                [OwnerIdType] int   NOT NULL CONSTRAINT [DF_fcp_factfindBase_OwnerIdType] DEFAULT (8) ,

                [OwningBusinessUnit] uniqueidentifier   NULL  ,

                [statecode] int   NOT NULL  ,

                [statuscode] int   NULL  ,

                [VersionNumber] timestamp   NULL  ,

                [ImportSequenceNumber] int   NULL  ,

                [OverriddenCreatedOn] datetime   NULL  ,

                [TimeZoneRuleVersionNumber] int   NULL  ,

                [UTCConversionTimeZoneCode] int   NULL  ,

                [fcp_factfindid] nvarchar(100)   NULL  ,

                [processid] uniqueidentifier   NULL  ,

                [stageid] uniqueidentifier   NULL  ,

                [traversedpath] nvarchar(1250)   NULL  ) Exception: System.Data.SqlClient.SqlException (0x80131904): Column names in each table must be unique. Column name 'fcp_factfindid' in table 'fcp_factfindBase' is specified more than once.

   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)

   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)

   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)

   at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)

   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)

   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()

   at Microsoft.Crm.CrmDbConnection.InternalExecuteWithRetry[TResult](Func`1 ExecuteMethod, IDbCommand command)

   at Microsoft.Crm.CrmDbConnection.InternalExecuteNonQuery(IDbCommand command, Boolean capturePerfTrace)

   at Microsoft.Crm.CrmDbConnection.ExecuteNonQuery(IDbCommand command, Boolean impersonate, Boolean capturePerfTrace)

   at Microsoft.Crm.Metadata.SqlHelper.ExecuteNonQuery(ISqlExecutionContext context, IDbCommand sqlCommand)

ClientConnectionId:655e6de1-4651-47d1-b347-c51d6f48365a

Error Number:2705,State:3,Class:16

[2015-07-23 13:49:25.563] Process: w3wp |Organization:8c07a7e5-8a21-e511-80bc-0050568c61d1 |Thread:   30 |Category: Platform.Metadata |User: 00000000-0000-0000-0000-000000000000 |Level: Error |ReqId: a03e2e2e-5ce9-4920-83c3-bc6edfc70ea1 | EntityService.Create  ilOffset = 0xB1

>EntityService.Create caught exception: System.Data.SqlClient.SqlException (0x80131904): Column names in each table must be unique. Column name 'fcp_factfindid' in table 'fcp_factfindBase' is specified more than once.

   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)

   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)

   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)

   at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error adding custom entity: auto SQL tries to add duplicate field

    Hi Aiden

    Thanks for your response. Yes, I believe you're right. Your suggestion was how I solved the problem.

    Thanks

    James

  • Suggested answer
    Aiden Kaskela Profile Picture
    Aiden Kaskela 19,692 on at
    RE: Error adding custom entity: auto SQL tries to add duplicate field

    Hi James,

    Is it possible the primary name field you were setting was "Fact Find Id", a text field? That would explain the issue, since the primary key would always be prefix_entityId and would be duplicated. I bet if you tried to set the primary name field to just "Fact Find" or "Fact Find Name", it would've been fine.

    Thanks,

     Aiden

  • ACECORP Profile Picture
    ACECORP 1,579 on at
    RE: Error adding custom entity: auto SQL tries to add duplicate field

    Ahh my bad... my problem is actually different... I replied to the wrong thread... sorry about that..

    My problem is explained here - https://community.dynamics.com/crm/f/117/t/170749

    It's some kind of odd timeout error.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error adding custom entity: auto SQL tries to add duplicate field

    I didn't get any responses but I did figure it out myself in the end.

    Basically, under the Primary Key tab don't change the name of the Name field (i.e. leave it as prefix_name).

    Hope this works for you. Interested to hear if it works.

    James

  • ACECORP Profile Picture
    ACECORP 1,579 on at
    RE: Error adding custom entity: auto SQL tries to add duplicate field

    Did you ever get a fix for this? I am experiencing the exact same issue.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans