microsoft / navcontainerhelper

Official Microsoft repository for BcContainerHelper, a PowerShell module, which makes it easier to work with Business Central Containers on Docker.
MIT License
382 stars 243 forks source link

Restore the backup from your online environment - Microsoft.Data.Tools.Schema.Sql.Build.SqlPackageException: File contains corrupted data #2007

Closed jngillard closed 2 years ago

jngillard commented 3 years ago

Following this post: https://freddysblog.com/2021/03/02/restoring-your-online-business-central-database-locally/

On section: Restore the backup from your online environment

I downloaded the .bacpac to my docker server.

This command: $ApploadBac = [Microsoft.SqlServer.Dac.BacPackage]::Load($backupFile) fails with Exception calling "Load" with "1" argument(s): "Could not load package from 'C:\Users\jgillard.WSI\AppData\Local\Temp\Production_20210715_01.bacpac'." At line:1 char:1

I tried to restore the bacpac using sql management studio and it says that the bacpac is corrupted? I'm not sure how to proceed to resolve restoring the SAAS .bacpac file to my local docker SQL server.

Any suggestions to try for resolving would be appreciated.

Here is the FULL ERROR output:

Exception : System.Management.Automation.MethodInvocationException: Exception calling "Load" with "1" argument(s): "Could not load package from 'C:\Users\jgillard.WSI\AppData\Local\Temp\Production_20210715_01.bacpac'." ---> Microsoft.SqlServer.Dac.DacServicesException: Could not load package from 'C:\Users\jgillard.WSI\AppData\Local\Temp\Production_20210715_01.bacpac'. ---> Microsoft.Data.Tools.Schema.Sql.Build.SqlPackageException: File contains corrupted data. ---> System.IO.FileFormatException: File contains corrupted data. at MS.Internal.IO.Zip.ZipIOLocalFileBlock.Validate(String fileName, ZipIOCentralDirectoryBlock centralDir, ZipIOCentralDirectoryFileHeader centralDirFileHeader) at MS.Internal.IO.Zip.ZipIOLocalFileBlock.SeekableLoad(ZipIOBlockManager blockManager, String fileName) at MS.Internal.IO.Zip.ZipIOBlockManager.LoadLocalFileBlock(String zipFileName) at MS.Internal.IO.Zip.ZipArchive.GetFile(String zipFileName) at MS.Internal.IO.Zip.ZipArchive.GetFiles() at System.IO.Packaging.ZipPackage.ContentTypeHelper..ctor(ZipArchive zipArchive, IgnoredItemHelper ignoredItemHelper) at System.IO.Packaging.ZipPackage..ctor(String path, FileMode mode, FileAccess access, FileShare share, Boolean streaming) at System.IO.Packaging.Package.Open(String path, FileMode packageMode, FileAccess packageAccess, FileShare packageShare, Boolean streaming) at Microsoft.Data.Tools.Schema.Sql.Build.SqlPackage.Artifact.InitializefromFile(FileInfo fileInfo, FileMode mode, FileAccess access) --- End of inner exception stack trace --- at Microsoft.Data.Tools.Schema.Sql.Build.SqlPackage.Artifact.InitializefromFile(FileInfo fileInfo, FileMode mode, FileAccess access) at Microsoft.Data.Tools.Schema.Sql.Build.SqlPackage.Open(FileInfo fileInfo, FileAccess access) at Microsoft.SqlServer.Dac.DacPackage.ContainsExportedData(IPackageSource packageSource) at Microsoft.SqlServer.Dac.BacPackage..ctor(IPackageSource packageSource) at Microsoft.SqlServer.Dac.BacPackage.Load(String fileName, DacSchemaModelStorageType modelStorageType) --- End of inner exception stack trace --- at Microsoft.SqlServer.Dac.BacPackage.Load(String fileName, DacSchemaModelStorageType modelStorageType) at CallSite.Target(Closure , CallSite , Type , Object ) --- End of inner exception stack trace --- at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) TargetObject : CategoryInfo : NotSpecified: (:) [], MethodInvocationException FullyQualifiedErrorId : DacServicesException ErrorDetails : InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at , : line 3 PipelineIterationInfo : {}

jngillard commented 3 years ago

I found this: https://community.dynamics.com/365/financeandoperations/f/dynamics-365-for-finance-and-operations-forum/381058/issue-in-database-restore-from-uat-to-sandbox

Running the restore using SQLPackage seems to be working... I'll update this again once it either completes / fails.

freddydk commented 3 years ago

Thanks for the info. Let me know how this goes, then I will update the reference to SQLPackage in ContainerHelper (and in the generic image)

jngillard commented 3 years ago

Hi Freddy: I was able to get the DB to restore using the SQLPackage. (It took forever.. but did finish) I've run into one further issue that I've not been able to resolve and can't seem to find anything about. When I try and login to the business central environment I am getting this error: image

I'm not sure what can be wrong. Any ideas?

jngillard commented 3 years ago

This is the event log details from the docker container:

The description for Event ID 705 from source MicrosoftDynamicsNavServer$BC cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

If the event originated on another computer, the display information had to be saved with the event.

The following information was included with the event:

Server instance: BC Category: License ClientSessionId: 5f6d43ea-4bd1-4533-a056-d7cca2a1f790 ClientActivityId: 22ddeeb8-c656-43d7-a41e-fc89a507e028 ServerSessionUniqueId: 5b5872c0-b00d-403c-9aaf-00605e9a18ce ServerActivityId: 364f8988-9915-4bbe-924d-bd1b6d48bce1 EventTime: 07/21/2021 15:44:46 Message (NavCSideException): An attempt of inserting an invalid tenant state license record has been made. Current state: Paid - New state: Trial Current start date: 06/10/2021 19:33:02 - New start date: 07/21/2021 15:44:46 Current end state: 01/01/0001 00:00:00 - New end state: 08/20/2021 15:44:46 RootException: NavCSideException Error Code:0 The trial edition has been already used. ExceptionStackTrace: at Microsoft.Dynamics.Nav.Runtime.TenantLicenseStateHelper.ValidateStateTransition(TenantLicenseState currentState, TenantLicenseState newState) at Microsoft.Dynamics.Nav.Runtime.SystemTableTriggers.OnBeforeInsertTenantLicenseState(MutableRecordBuffer recordBuffer) CallerStackTrace: at Microsoft.Dynamics.Nav.Runtime.SystemTableTriggers.OnBeforeInsertTenantLicenseState(MutableRecordBuffer recordBuffer) at Microsoft.Dynamics.Nav.Runtime.SystemTableTriggers.OnBeforeInsert(MutableRecordBuffer recordBuffer) at Microsoft.Dynamics.Nav.Runtime.TransactionalDataCache.OnBeforeInsert(Int32 companyToken, MutableRecordBuffer recordBuffer, Int32& transactionBumperToken, Action1& onAfterInsert) at Microsoft.Dynamics.Nav.Runtime.DataAccess.Insert(Int32 companyToken, MutableRecordBuffer recordBuffer, InsertOptions options, MutableRecordBuffer& newRecordBuffer) at Microsoft.Dynamics.Nav.Runtime.RecordImplementation.InsertRecord(DataError errorLevel) at Microsoft.Dynamics.Nav.Runtime.NavRecord.Insert(DataError errorLevel, Boolean runApplicationTrigger, Boolean runGlobalTrigger, Boolean insertWithSystemId) at Microsoft.Dynamics.Nav.Runtime.NavRecord.ALInsert(DataError errorLevel, Boolean runApplicationTrigger, Boolean insertWithSystemId) at Microsoft.Dynamics.Nav.Runtime.TenantLicenseStateHelper.InsertNewState(NavRecord tenantLicenseStateRec, TenantLicenseState newState) at Microsoft.Dynamics.Nav.Runtime.TenantLicenseStateHelper.InsertTrialState(NavSession session) at Microsoft.Dynamics.Nav.Runtime.NavSession.EnsureTrialStarted() at Microsoft.Dynamics.Nav.Service.NSService.OpenCompany(String companyName, Boolean overridePersonalization) at SyncInvokeOpenCompany(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.ErrorMappingCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs) at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass28_1.<Combine>b__1(NSServiceBase serviceInstance, Object[] inputs, Object[]& outputs) at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.PushPopCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs) at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass28_1.<Combine>b__1(NSServiceBase serviceInstance, Object[] inputs, Object[]& outputs) at Microsoft.Dynamics.Nav.Service.ServiceOperationTracer.TraceScopeCombinator(Category telemetryCategory, ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs) at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass28_1.<Combine>b__1(NSServiceBase serviceInstance, Object[] inputs, Object[]& outputs) at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass10_0.<PerformanceCounterCombinator>b__0() at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.PerformanceCounterCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs) at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass28_1.<Combine>b__1(NSServiceBase serviceInstance, Object[] inputs, Object[]& outputs) at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.InitClientTelemetryIdsCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs) at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass28_1.<Combine>b__1(NSServiceBase serviceInstance, Object[] inputs, Object[]& outputs) at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.TlsClearCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs) at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass28_1.<Combine>b__1(NSServiceBase serviceInstance, Object[] inputs, Object[]& outputs) at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet) at System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext) at System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext) at System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult result) at System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult result) at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) at Microsoft.Dynamics.Nav.Types.Channels.ReceiveCorrelator.AsyncResult.Complete(Action setValue) at Microsoft.Dynamics.Nav.Types.Channels.ReceiveCorrelator.OnNewMessage(IAsyncResult ar) at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously) at System.ServiceModel.Security.SecuritySessionServerSettings.ServerSecuritySessionChannel.ReceiveRequestAsyncResult.Complete(Boolean synchronous, Exception exception) at System.ServiceModel.Security.SecuritySessionServerSettings.ServerSecuritySessionChannel.ReceiveRequestAsyncResult.OnReceive(IAsyncResult result) at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously) at System.ServiceModel.Channels.ReliableChannelBinder1.InputAsyncResult1.OnInputComplete(IAsyncResult result) at System.ServiceModel.Channels.ReliableChannelBinder1.InputAsyncResult`1.OnInputCompleteStatic(IAsyncResult result) at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously) at System.ServiceModel.Channels.TransportDuplexSessionChannel.TryReceiveAsyncResult.OnReceive(IAsyncResult result) at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously) at System.ServiceModel.Channels.SynchronizedMessageSource.ReceiveAsyncResult.OnReceiveComplete(Object state) at System.ServiceModel.Channels.SessionConnectionReader.OnAsyncReadComplete(Object state) at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) at System.Net.LazyAsyncResult.Complete(IntPtr userToken) at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken) at System.Net.Security._SslStream.ProcessFrameBody(Int32 readBytes, Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security._SslStream.ReadFrameCallback(AsyncProtocolRequest asyncRequest) at System.Net.AsyncProtocolRequest.CompleteRequest(Int32 result) at System.Net.FixedSizeReader.CheckCompletionBeforeNextRead(Int32 bytes) at System.Net.FixedSizeReader.ReadCallback(IAsyncResult transportResult) at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously) at System.ServiceModel.Channels.ConnectionStream.IOAsyncResult.OnAsyncIOComplete(Object state) at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e) at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(SocketError socketError, Int32 bytesTransferred, SocketFlags flags) at System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped nativeOverlapped) at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped pOVERLAP)

ProcessId: 1176 Tag: 00000EI ThreadId: 178 CounterInformation: CustomParameters: { } GatewayCorrelationId:

freddydk commented 3 years ago

Are you specifying a license file?

freddydk commented 3 years ago

QQ - you used the dotnet core version right? Did you try the restore with the MSI version for Windows? The version pointed out by the blog post was 18.2 - the latest is 18.7 I have updated the blog post to point to 18.7 instead and will try myself next week (after my vacation)

jngillard commented 3 years ago

I re-ran the process over again. I think the main issue here was that I had uninstalled the base business central application extensions in error earlier in the process.

I did run into the issue with "you are not licensed for production companies", but that was resolved by:

Write-Host "USE [$databaseName] UPDATE [dbo].[Company] SET [Evaluation Company] = 1 WHERE Name = 'COMPANYNAME'" Invoke-Sqlcmd -Query "USE [$databaseName] UPDATE [dbo].[Company] SET [Evaluation Company] = 1 WHERE Name = 'COMPANYNAME'" Restart-NavContainer -containerName $containerName

Then using that company to login.