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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

DynamicsAxCommunity PowerShell module - Sync DB

(0) ShareShare
ReportReport
Posted on by

Hello,

I am using the DynamicsAxCommunity PowerShell module. When I am running the DB Sync (Synchronize-AXDatabase), I get an error of "No matches found". If I run the DB Sync manually, everything works fine. I am unsure of what the error means. Does anyone have any ideas? I suppose I could just code to accept this, but I'd prefer to understand what the problem is and fix it if possible.

Thanks in advance!!!

Tony

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at

    I'm the author of the module, so I'll do my best to help you. Nevertheless I'm unable to say what happened from the current description. Doesn't the error contain any more information? Which version of the module do you use? Are you able to debug the script to see where exactly is fails?

  • Community Member Profile Picture
    on at

    Hi Martin,

    Here is the code I am running:

    Function Sync-DB

    {

       Write-Output("Start Sync-DB");

    #Sleep for three minutes to ensure CIL Generation is complete and released.

    Start-Sleep -Seconds 180;

       #Log output to text file. If there is a DB Sync issue, this will not finish and will time out.

       Set-Location "$Script:OutputDirectory\";

       $DateTimeNow = Get-Date;

       Add-Content $Script:DBSyncTextFile $DateTimeNow;

       Add-Content $Script:DBSyncTextFile 'Starting DB Sync';

       Add-Content $Script:DBSyncTextFile ' ';

       $Script:ErrorCount = $Error.Count;

       If ($Script:TestMode -ne "true")

           {Synchronize-AXDatabase -ConfigPath "$Script:DBSyncAxc" -Timeout (New-TimeSpan -Hours 2).TotalSeconds;}

       If ($Error.Count -eq $Script:ErrorCount)

       {

           $DateTimeNow = Get-Date;

           Add-Content $Script:DBSyncTextFile $DateTimeNow;

           Add-Content $Script:DBSyncTextFile 'DB Sync Complete';

       }

       Else

       {

           #DB Sync Failed - do not report this as an actual error in the script.

           $Script:ErrorsAllowed++;

           $DateTimeNow = Get-Date;

           Add-Content $Script:DBSyncTextFile $DateTimeNow;

           Add-Content $Script:DBSyncTextFile 'DB Sync appears to have failed - run manually to see errors';

           Add-Content $Script:DBSyncTextFile $Error[$Error.Count -1];

       }

       Write-Output("End Sync-DB");

    }

    When I run this manually, no errors occur, so it's tough to debug. I just run it through a task scheduler and it runs fine. I think I'm going to try running it an hour later just to see if that makes any difference. It may be possible something else is going on that I am unaware of that is causing this.

  • Community Member Profile Picture
    on at

    Sorry - let me clarify this. If I manually do a DB Sync by going into the AOT, right clicking Data Dictionary and selecting "Synchronize", it works fine. If I run this code in Powershell, I get that error. Obviously trying to run it at a different time will make no difference. If it comes to it, I can just handle that this error is reported back.

  • Community Member Profile Picture
    on at

    I found the code. It's in DynamicsAxCommunity.psm1 on line 1318:

    $lastErrorMsg = Get-EventLog -LogName "Application" -Source "Microsoft Dynamics AX" -EntryType "Error" -InstanceId 110 `

    -After ($eventsAfter) -ErrorAction SilentlyContinue | select -expand ReplacementStrings -First 1 | where {$_}

    Is it because we don't have any criteria that matches this? We do not have any failures for source "Microsoft Dynamics AX" Type "Error" and InstanceId of 110. Other environments where this runs fine, there are events that match this criteria.

  • Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at

    This code is an attempt to detect situations when the script can't connect to AX (otherwise it would just got stuck). These error conditions are the trickiest part of automation of AX, because AX doesn't provide any reasonable feedback.

    I don't like this solution, but I didn't come then with anything better without changing code in AX. Unfortunately introducing a dependency in AX would render the module much less useful.

    Back to your problem. Unfortunately I don't know how to reproduce it, so I depend on you. Will you get the same error if you run the code in isolation (just set $startTime = Get-Date)? I assume you will, which will make our debugging easier. Then we could use a debugger or split the command to several smaller chunks to see what exactly fails.

    By the way, which version of Powershell do you use?

  • Community Member Profile Picture
    on at

    Sorry - forgot to put that earlier. I think this is the version info you are looking for, correct? I see this in DynamicsAxCommunity.psd1

    ModuleVersion = '0.3.4'

    I understand what you are saying, but I do love what you have done creating these modules. So thank you for doing them!

    It appears to me that these parms are what cause the error - with either of these included, I get the error:

    -EntryType "Error" -InstanceId 110

    If I remove those, it does not error. I think you could maybe reproduce it if you change it to -InstanceId 111. Here is my code I am playing around with:

    Clear-Host;

    $startTime = Get-Date;

    $eventsAfter = $startTime.Subtract((New-TimeSpan -Seconds 1)) #Remove one second to see events occured in the same second when process started

    $Error.Clear();

    $Error.Count;

    #$lastErrorMsg = Get-EventLog -LogName "Application" -Source "Microsoft Dynamics AX" -EntryType "Error" -InstanceId 110 -After ($eventsAfter) -ErrorAction SilentlyContinue | select -expand ReplacementStrings -First 1 | where {$_}

    $lastErrorMsg = Get-EventLog -LogName "Application" -Source "Microsoft Dynamics AX" -InstanceId 111

    $Error.Count;

    $Error[$Error.Count -1];

  • Community Member Profile Picture
    on at

    Martin - thanks again for your help. I just ran this on the machine:

    eventcreate /L APPLICATION /T ERROR /SO "Microsoft Dynamics AX" /ID 110 /D "Fix for Powershell Module"

    Now the DB Sync works fine. If you do modify the powershell module, please let me know, but this works fine for me now.

    Thanks again!

  • Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at

    To be able to fix something and test that the fix is effective, I first must be able to reproduce the problem. Unfortunately even if I use completely made up log source, I don't get any error. Can you also try the following piece of code?

    $lastErrorMsg = Get-EventLog -LogName "Application" -Source "This doesn't exist for sure, right?" -EntryType "Error" -InstanceId 110 -ErrorAction SilentlyContinue | select -expand ReplacementStrings -First 1 | where {$_}

    Also, can you please tell me which version of Powershell do you use? Use Get-Host to find it. Maybe there is a difference between versions and I test it on a different version than you.

  • Community Member Profile Picture
    on at

    I am using PowerShell version 3.0

    When I run the code you specified, I do not get an error. However, if I change the code to look for InstanceId 111, I do get it. Just to be clear - I am looking at $Error.Count. If I do not actually look at that, no error is actually reported back - I assume because of the "SilentlyContinue" parm.

    Here is the code I am running where I see the error (note the InstanceId of 111 not 110):

    Clear-Host;

    $startTime = Get-Date;

    $eventsAfter = $startTime.Subtract((New-TimeSpan -Seconds 1)) #Remove one second to see events occured in the same second when process started

    $Error.clear();

    $Error.Count;

    $lastErrorMsg = Get-EventLog -LogName "Application" -Source "This doesn't exist for sure, right?" -EntryType "Error" -InstanceId 111 -ErrorAction SilentlyContinue | select -expand ReplacementStrings -First 1 | where {$_};

    $Error.Count;

    $Error[$Error.Count -1];

  • Verified answer
    Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at

    Aha, I finally see what you did. You dug out the error that I already handled by SilentlyContinue. Of course that there may be no event in the log and Get-EventLog returns "No matches found" in that case. But that's not an error for us - it actually means that there is no error that all. So the module explicitly doesn't care and continues without any error.

    Sure, I could use Ignore instead SilentlyContinue these days, but it wasn't available when I wrote the module (in days of in Powershell 2.0).

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans