web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Microsoft Dynamics for Finance Onprem DBSync error

(0) ShareShare
ReportReport
Posted on by 4

I'm having a problem finishing up an on-premise setup of Microsoft Dynamics. The issue is an AosSqlDatastack Error. The DBSync package scripts seem to be creating bad SQL create view statements. The version being provisioned dis 10.0.46. I don't know if anyone else is facing this issue and how it is being solved. After every sql data stack error the AOS is marked as dead. I have rerun the update several times and the AOS machines take turns and eventually fail. dropping the views doesn't help at all. Here are the malformed queries and the errors pasted below. Any suggestions will be highly appreciated. Thank you.

An expression of non-boolean type specified in a context where a condition is expected, near 'AND'.

  callStack at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 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(TaskCompletionSource1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.SqlCommandExtensions.<>c__DisplayClass1.b__0() at Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy.ExecuteAction[TResult](Func1 func) at Microsoft.Dynamics.AX.Data.Sql.SqlDataAccessManager.b__35_0(SqlCommand c) at Microsoft.Dynamics.AX.Data.Sql.SqlDataAccessManager.ExecuteSql[T](SqlCommand cmd, Func2 sqlFunc, String loggableStatement)

  statement CREATE VIEW [DBO].[PURCHREQTABLEMYREQUISITIONSVIEW] AS SELECT T1.RECID AS PURCHREQRECID, T1.PARTITION AS PARTITION, T1.RECID AS RECID FROM PURCHREQTABLE T1 WHERE EXISTS (SELECT TOP 1 ' x ' FROM PURCHREQLINE T2 WHERE( 0 AND (( T1.RECID = T2.PURCHREQTABLE) AND ( T1.PARTITION = T2.PARTITION))))

  errorCode 4145

  sqlState 1

 AXDB

  errorMessage An expression of non-boolean type specified in a context where a condition is expected, near 'AND'.

  callStack at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 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(TaskCompletionSource1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.SqlCommandExtensions.<>c__DisplayClass1.b__0() at Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy.ExecuteAction[TResult](Func1 func) at Microsoft.Dynamics.AX.Data.Sql.SqlDataAccessManager.b__35_0(SqlCommand c) at Microsoft.Dynamics.AX.Data.Sql.SqlDataAccessManager.ExecuteSql[T](SqlCommand cmd, Func2 sqlFunc, String loggableStatement)

  statement CREATE VIEW [DBO].[SALESORDERUPDATELINESPARAMETERSENTITY] AS SELECT T1.TABLE2LINEUPDATE AS SALESORDERLINEUPDATERULE, T1.FIELDID AS FIELDID, T1.RECVERSION AS RECVERSION, T1.DATAAREAID AS DATAAREAID, T1.PARTITION AS PARTITION, T1.RECID AS RECID, T2.NAME AS SALESORDERHEADERFIELDNAME, T2.RECVERSION AS RECVERSION#2, T2.RECID AS RECID#2 FROM SALESTABLE2LINEPARAMETERS T1 CROSS JOIN SQLDICTIONARY T2 WHERE(( N'35,44,45,51,53,97,105,106,109,135,146,160,206' AND ( T2.TABLEID = 22489)) AND ( T1.FIELDID = T2.FIELDID))

  errorCode 4145

AXDB

  errorMessage An expression of non-boolean type specified in a context where a condition is expected, near 'GROUP'.

  callStack at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 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(TaskCompletionSource1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.SqlCommandExtensions.<>c__DisplayClass1.b__0() at Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy.ExecuteAction[TResult](Func1 func) at Microsoft.Dynamics.AX.Data.Sql.SqlDataAccessManager.b__35_0(SqlCommand c) at Microsoft.Dynamics.AX.Data.Sql.SqlDataAccessManager.ExecuteSql[T](SqlCommand cmd, Func2 sqlFunc, String loggableStatement)

  statement CREATE VIEW [DBO].[MARKUPTRANSLINETOTALCHARGEAMOUNTVIEW] AS SELECT SUM(T1.CALCULATEDAMOUNT) AS CHARGEAMOUNT, T1.TRANSRECID AS CUSTINVOICETRANSRECID, T1.DATAAREAID AS DATAAREAID, T1.PARTITION AS PARTITION, 1010 AS RECID FROM MARKUPTRANS T1 WHERE N'25583' GROUP BY T1.TRANSRECID, T1.DATAAREAID, T1.PARTITION

An expression of non-boolean type specified in a context where a condition is expected, near ')'. Incorrect syntax near ')'. Incorrect syntax near ')'.

  callStack at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 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(TaskCompletionSource1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.SqlCommandExtensions.<>c__DisplayClass1.b__0() at Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy.ExecuteAction[TResult](Func1 func) at Microsoft.Dynamics.AX.Data.Sql.SqlDataAccessManager.b__35_0(SqlCommand c) at Microsoft.Dynamics.AX.Data.Sql.SqlDataAccessManager.ExecuteSql[T](SqlCommand cmd, Func2 sqlFunc, String loggableStatement)

  statement CREATE VIEW [DBO].[RETAILACTIVEDISCOUNTS] AS SELECT T1.NAME AS NAME, T1.RECID AS DISCOUNTRECID, T1.OFFERID AS OFFERID, T1.DATAAREAID AS DATAAREAID, T1.PARTITION AS PARTITION, T1.RECID AS RECID FROM RETAILPERIODICDISCOUNT T1 WHERE(((((( T1.VALIDFROM < '09/28/2026 00:00:00') AND ( T1.VALIDTO > '09/26/2026 00:00:00')) AND ( T1.STATUS = 1)) AND N'Simple\ discount,Discount\ with\ quantity\ limit,Least\ expensive\ favor\ retailer,Mix\ and\ match\ discount,Quantity\ discount,Threshold\ discount,Free\ item') AND EXISTS (SELECT TOP 1 ' x ' FROM RETAILDISCOUNTPRICEGROUP T2 WHERE(((( T1.OFFERID = T2.OFFERID) AND ( T1.DATAAREAID = T2.DATAAREAID)) AND ( T1.PARTITION = T2.PARTITION)) AND EXISTS (SELECT TOP 1 ' x ' FROM RETAILCHANNELPRICEGROUP T3 WHERE((( T2.PRICEDISCGROUP = T3.PRICEGROUP) AND ( T2.PARTITION = T3.PARTITION)) AND EXISTS (SELECT TOP 1 ' x ' FROM RETAILCHANNELTABLE T4 WHERE((( T3.RETAILCHANNEL = T4.RECID) AND ( T3.PARTITION = T4.PARTITION)) AND EXISTS (SELECT TOP 1 ' x ' FROM OMEXPLODEDORGANIZATIONSECURITYGRAPH T5 WHERE((( T4.OMOPERATINGUNITID = T5.ORGANIZATION) AND ( T4.PARTITION = T5.PARTITION)) AND EXISTS (SELECT TOP 1 ' x ' FROM OMHIERARCHYRELATIONSHIP T6 WHERE(( T5.ANCESTORORGANIZATION = T6.CHILDORGANIZATION) AND ( T5.PARTITION = T6.PARTITION)))))))))))) AND EXISTS (SELECT TOP 1 ' x ' FROM RETAILPERIODICDISCOUNTLINE T7 WHERE(((( T1.OFFERID = T7.OFFERID) AND ( T1.DATAAREAID = T7.DATAAREAID)) AND ( T1.PARTITION = T7.PARTITION)) AND EXISTS (SELECT TOP 1 ' x ' FROM RETAILGROUPMEMBERLINE T8 WHERE((( T7.RETAILGROUPMEMBERLINE = T8.RECID) AND ( T7.PARTITION = T8.PARTITION)) AND EXISTS (SELECT TOP 1 ' x ' FROM ECORESCATEGORY T9 WHERE((( T8.CATEGORY = T9.RECID) AND ( T8.PARTITION = T9.PARTITION)) AND EXISTS (SELECT TOP 1 ' x ' FROM ECORESCATEGORYHIERARCHY T10 WHERE(( T9.CATEGORYHIERARCHY = T10.RECID) AND ( T9.PARTITION = T10.PARTITION))))))))))

  errorCode 4145

  • Anton Venter Profile Picture
    21,288 Super User 2026 Season 2 on at

    @CU29090722-1 

    Just a thought and you will have to check this, but perhaps your SQL Server needs to be upgraded to a newer version? Are there any chance any extensions on the views causing errors?

  • Martin Dráb Profile Picture
    241,313 Most Valuable Professional on at

    In all cases. it's caused by the WHERE clause having a static value instead of the condition (a field name, an operator, a value).

    Namely:

    • 0
    • N'35,44,45,51,53,97,105,106,109,135,146,160,206'
    • N'25583'
    • N'Simple\ discount,Discount\ with\ quantity\ limit,Least\ expensive\ favor\ retailer,Mix\ and\ match\ discount,Quantity\ discount,Threshold\ discount,Free\ item'

     

    Check the view definitions (including extensions) in Visual Studio, maybe you'll notice some pattern.

     

    If I look at the last one, RetailActiveDiscounts, the condition (in the standard application) is PeriodicDiscountType = [the return value of RetailPeriodicDiscountQueriesHelper::getDiscountOfferTypes()], with this resulting SQL code:

     

    AND (PERIODICDISCOUNTTYPE = 2 OR
     PERIODICDISCOUNTTYPE = 6 OR
     PERIODICDISCOUNTTYPE = 5 OR
     PERIODICDISCOUNTTYPE = 1 OR
     PERIODICDISCOUNTTYPE = 0 OR
     PERIODICDISCOUNTTYPE = 4 OR
     PERIODICDISCOUNTTYPE = 8) 

     

    In your case, both the field name and the operator are missing, and the value is wrong too. I don't know why.

  • KentChidi Profile Picture
    4 on at

    Thanks for the replies. This is a sqlserver 2022 installation. These scripts are coming from the deployment package. There are about 16 views with these malformed queries. Could this be a bug in the package? how do I use VS to inspect this. I'll look into this. Give me some hints. Thanks.

  • KentChidi Profile Picture
    4 on at

    Also please note that this is not a VM installation. It's a full deployment environemnt I'm deploying from LCS. Thank you.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 507 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 419 Super User 2026 Season 2

#3
CU-1234529-002 Profile Picture

CU-1234529-002 155

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans