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.