Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Dynamics V9 Search for an entity field give a generic SQL error when lookup text is added

Posted on by

Hi

I have migrated my 8.2 bd to 9 on premises, browsing the web to check all is working well, i found an error, when trying to put a contact, or parent account the search failed when a put some on the field, whitout text the search works.

eneric SQL error. ---> System.Data.SqlClient.SqlException: Incorrect syntax near ')'.
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.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at Microsoft.Crm.CrmDbConnection.InternalExecuteWithRetry[TResult](Func`1 ExecuteMethod, IDbCommand command)
at Microsoft.Crm.CrmDbConnection.<>c__DisplayClass104_0.<InternalExecuteReader>b__0()
at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute[TResult](ILogger logger, EventI

*This post is locked for comments

  • Suggested answer
    jimmy07 Profile Picture
    jimmy07 35 on at
    RE: Dynamics V9 Search for an entity field give a generic SQL error when lookup text is added

    This is a bug in v9. It has been fixed in 9.07.

    support.microsoft.com/.../dynamics-on-premises-elevation-of-privilege-vulnerability-august-13-2019-9cf9c245-ba2f-ea73-5cc6-4e416e5de64d

    It’s the third item from the bottom.

  • Shlomi Profile Picture
    Shlomi 15 on at
    RE: Dynamics V9 Search for an entity field give a generic SQL error when lookup text is added

    Hi

    Have you found a solution?

  • jimmy07 Profile Picture
    jimmy07 35 on at
    RE: Dynamics V9 Search for an entity field give a generic SQL error when lookup text is added

    Hi, I found the same error in our V9.0.3.7. Have your problem been fixed? Could you pls let me know how you fixed it?

    Thx

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Dynamics V9 Search for an entity field give a generic SQL error when lookup text is added

    don't add only lookup text this error could occour in a generic sql entry, no full index search is enable  check parent account in contact form.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Dynamics V9 Search for an entity field give a generic SQL error when lookup text is added

    Same issue here, upgraded from 8.1.1 to 9.0 internally the query being executed on the database while FullTextIndex being enabled throws Incorrect syntax near ')' making me think there's an error by the CRM while building the FullTextQuery. Having the FullTextIndex disabled creates a different query which indeed works.

    I will probably open a support ticket to MS.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Dynamics V9 Search for an entity field give a generic SQL error when lookup text is added

    If you are interested, these are the steps we followed to understand the error better, starting from the beginning of creating a new organization without any solutions imported. It appears that CRM is not correctly constructing the SQL statement for full text searches.

    • In deployment manager, create a new organization.
    • Enable full text search for Quick Find.
      • Settings > Administration > System Settings > Enable full-text Search for QuickFind.
      • Confirm that the contact is an entity selected for search.
      • Check the QuickFind view of the contact entity to ensure last name is included as searchable field.
    • Create a contact record with a last name of “Van Horne”
    • Normally, we would wait 24 hours before expecting the full text-search to be fully enabled. But because we just installed a new organization as indicated above, we have to wait at least 34 hours from the time of installation. Determining the exact time seems to be possible by running the following SQL and confirming the last run time (UTC) and next run time of the Index Management job for the new organization:

    select o.FriendlyName, mj.* FROM [MSCRM_CONFIG].[dbo].[ScaleGroupOrganizationMaintenanceJobs] mj, [MSCRM_CONFIG].[dbo].Organization o WHERE o.Id = mj.OrganizationId AND mj.OperationType = 15

    • Confirm that CRMFullTextCatalog at the database level now contains the contact entity and its fields
      • Use SQL Server Profiler to trace the event “Stored Procedure > RPC:Completed”
      • Use QuickFind on the contact entity to search for “Horne”. This should return the record but instead produces a SQL error.
      • Stop SQL Server Profiler trace and search the text column for “QuickFind” and view the SQL. The SQL does not appear to have been constructed properly to do a full-text search. The SQL looks like this (notice the empty brackets on the first line):

    exec sp_executesql N'WITH __QuickFind__ as (select top 10001 [ContactId] from () as [__QuickFindInternal__])select

    top 51 "contact0".FullName as "fullname"

    , "contact0".ParentCustomerId as "parentcustomerid"

    , "contact0".Address1_City as "address1_city"

    , "contact0".Address1_Telephone1 as "address1_telephone1"

    , "contact0".Telephone1 as "telephone1"

    , "contact0".EMailAddress1 as "emailaddress1"

    , "contact0".ContactId as "contactid"

    , "contact0".ProcessId as "processid"

    , convert(bigint, "contact0".VersionNumber) as "versionnumber"

    , "contact0".ParentCustomerIdName as "parentcustomeridname"

    , "contact0".ParentCustomerIdType as "parentcustomeridtype"

    , "contact0".ParentCustomerIdYomiName as "parentcustomeridyominame"

    , case when (select COUNT(*) from [__QuickFind__]) = 10001 then 1 else 0 end as [__QuickFindLimitValue__]

    , convert(bigint, "processidworkflowworkflowid".VersionNumber) as "processidworkflowworkflowid.versionnumber"

    from

    Contact as "contact0"

            left outer join Workflow as "processidworkflowworkflowid" on ("contact0".ProcessId = "processidworkflowworkflowid".WorkflowId)

    where

    [contact0].[ContactId] in (select [ContactId] from [__QuickFind__]) and (("contact0".StateCode = @StateCode0))

    order by

    "contact0".FullName asc

    , "contact0".ContactId asc',N'@StateCode0 int,@FullName0 nvarchar(200),@FirstName0 nvarchar(200),@LastName0 nvarchar(200),@MiddleName0 nvarchar(200),@EMailAddress10 nvarchar(200),@ParentCustomerIdName0 nvarchar(200),@Telephone10 nvarchar(200),@MobilePhone0 nvarchar(200)',@StateCode0=0,@FullName0=N'((("Horne*" OR FORMSOF(FREETEXT, "Horne"))) OR ("Horne"))',@FirstName0=N'((("Horne*" OR FORMSOF(FREETEXT, "Horne"))) OR ("Horne"))',@LastName0=N'((("Horne*" OR FORMSOF(FREETEXT, "Horne"))) OR ("Horne"))',@MiddleName0=N'((("Horne*" OR FORMSOF(FREETEXT, "Horne"))) OR ("Horne"))',@EMailAddress10=N'((("Horne*" OR FORMSOF(FREETEXT, "Horne"))) OR ("Horne"))',@ParentCustomerIdName0=N'((("Horne*" OR FORMSOF(FREETEXT, "Horne"))) OR ("Horne"))',@Telephone10=N'((("Horne*" OR FORMSOF(FREETEXT, "Horne"))) OR ("Horne"))',@MobilePhone0=N'((("Horne*" OR FORMSOF(FREETEXT, "Horne"))) OR ("Horne"))'

    • On the database, the following query returns one row, proving that, at the database level, full text search appears to work.

    exec sp_executesql N'WITH __QuickFind__ as (select top 10001 [ContactId] from (

    SELECT "contact0".[Key] AS [ContactId] FROM ContainsTable([ContactBase], (FullName), @FullName0) AS "contact0") as [__QuickFindInternal__])select

    top 251 "contact0".FullName as "fullname"

    , "contact0".ContactId as "contactid"

    , "contact0".ProcessId as "processid"

    , convert(bigint, "contact0".VersionNumber) as "versionnumber"

    , case when (select COUNT(*) from [__QuickFind__]) = 10001 then 1 else 0 end as [__QuickFindLimitValue__]

    , convert(bigint, "processidworkflowworkflowid".VersionNumber) as "processidworkflowworkflowid.versionnumber"

    from

    Contact as "contact0" WITH (NOLOCK) left outer join Workflow as "processidworkflowworkflowid" WITH (NOLOCK) on ("contact0".ProcessId = "processidworkflowworkflowid".WorkflowId)

    where

    [contact0].[ContactId] in (select [ContactId] from [__QuickFind__]) and (((("contact0".StateCode = @StateCode0)))) order by

    "contact0".FullName asc

    , "contact0".ContactId asc',N'@StateCode0 int,@FullName0 nvarchar(200)',@StateCode0=0,

    @FullName0=N'((("Horne*" OR FORMSOF(FREETEXT, "Horne"))) OR ("Horne"))'


    We probably won't pursue this problem any further as we have recently decided to move from on-premises to online.  But perhaps the above information will help you troubleshoot the problem.

  • Paraya Profile Picture
    Paraya on at
    RE: Dynamics V9 Search for an entity field give a generic SQL error when lookup text is added

    I spoke too fast, error come back again.

    Re imported the org and the problem is still there.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Dynamics V9 Search for an entity field give a generic SQL error when lookup text is added

    Hi Paraya, when you say it works, I assume you mean that you do not get the SQL error any more. But does the functionality of the full text search actually work? For example, if you create a contact with a last name with a space like "Van Horne", and then search for "Horne", will it find the record? We also ran into this problem when we upgraded from V8.2 to V9 and have not resolved it.

  • Suggested answer
    Sreevalli Profile Picture
    Sreevalli 3,256 on at
    RE: Dynamics V9 Search for an entity field give a generic SQL error when lookup text is added

    Great, Happy CRMing!!

  • Paraya Profile Picture
    Paraya on at
    RE: Dynamics V9 Search for an entity field give a generic SQL error when lookup text is added

    Finally get it working

    The Generic Error was because, no index created for full-text search.

    Thanks

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans