Error on saving a document

Hi @emre

I am experiencing a very weird issue with saving a new created document transaction. Basically trying to create a new Document Type for a new Account Transaction Type for default Customer Entity Type.

I tried creating a whole new entity type, new account type, new transaction type and document type and I get the same error no matter what type of entity I use. Entity Types I am using dont have any Custom fields of any kind.

From the error I can see that there is an issue of some kind with sharing primary keys and core exceptions.

Whats very interesting that no matter what I do it ends up crashing but when I try to do the same thing on any other database its perfectly fine. I also tried exporting what I wanted from a working database and importing into this one and it just wont work.

For testing purposes I even tried copying the database on another machine, wiping the database and restoring it under a different name with different .mdf and .ldf but I get the same error. I really dont understand what could be wrong.

What I did notice was that even after wiping all the transactions in the database it was 855MB big, which is quite - odd.

[General Info]

Application: SambaPOS
Version:     5.2.18
Region:      en
DB:          SQ
Machine:     TECHASIA
User:        Stacey
Date:        23-02-19
Time:        14:16

User Explanation:

Stacey said ""

[Exception Info 1]

Top-level Exception
Type:        System.Reflection.TargetInvocationException
Message:     Exception has been thrown by the target of an invocation.
Source:      mscorlib
Stack Trace: at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Inner Exception 1
Type:        System.Data.Entity.Infrastructure.DbUpdateException
Message:     An error occurred while saving entities that do not expose foreign key properties for their relationships. The EntityEntries property will return null because a single entity cannot be identified as the source of the exception. Handling of exceptions while saving can be made easier by exposing foreign key properties in your entity types. See the InnerException for details.
Source:      EntityFramework
Stack Trace: at System.Data.Entity.Internal.InternalContext.SaveChanges()
   at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
   at System.Data.Entity.DbContext.SaveChanges()
   at Samba.Infrastructure.Data.SqlData.EFWorkspace.CommitChanges()
   at Samba.Presentation.Common.ModelBase.EntityCollectionViewModelBase`2.<.ctor>b__0_3(EventParameters`1 x)
   at Microsoft.Practices.Prism.Events.EventSubscription`1.InvokeAction(Action`1 action, TPayload argument)
   at Microsoft.Practices.Prism.Events.EventSubscription`1.<>c__DisplayClass2.<GetExecutionStrategy>b__0(Object[] arguments)
   at Microsoft.Practices.Prism.Events.EventBase.InternalPublish(Object[] arguments)
   at Microsoft.Practices.Prism.Events.CompositePresentationEvent`1.Publish(TPayload payload)
   at Samba.Presentation.Services.Common.ExtensionMethods.Publish[TEventsubject](TEventsubject eventArgs, String eventTopic, Action expectedAction)

Inner Exception 2
Type:        System.Data.Entity.Core.UpdateException
Message:     An error occurred while updating the entries. See the inner exception for details.
Source:      EntityFramework
Stack Trace: at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
   at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut)
   at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](T noChangesResult, Func`2 updateFunction)
   at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update()
   at System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__35()
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
   at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass2a.<SaveChangesInternal>b__27()
   at System.Data.Entity.Infrastructure.DbExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)
   at System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options)
   at System.Data.Entity.Internal.InternalContext.SaveChanges()

Inner Exception 3
Type:        System.Data.SqlClient.SqlException
Message:     Conversion failed when converting the nvarchar value '40167EECA364_A666_' to data type int.
Source:      .Net SqlClient Data Provider
Stack Trace: at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.SqlInternalConnection.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.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.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<NonQuery>b__0(DbCommand t, DbCommandInterceptionContext`1 c)
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext)
   at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteNonQuery()
   at System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary`2 identifierValues, List`1 generatedValues)
   at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()


[Assembly Info]

mscorlib, Version=
Samba.Services, Version=
Samba.Domain, Version=
Samba.Infrastructure.Data, Version=
System.ComponentModel.Composition, Version=
Samba.Presentation.Services, Version=
System.Core, Version=
PresentationCore, Version=
WindowsBase, Version=
DevExpress.Xpf.LayoutControl.v16.2, Version=
System.Xml, Version=
DevExpress.Xpf.Grid.v16.2, Version=
System, Version=
DevExpress.Xpf.Grid.v16.2.Core, Version=
System.Xaml, Version=
PresentationFramework, Version=
Samba.Infrastructure, Version=
Microsoft.Practices.Prism, Version=
System.Runtime.Serialization, Version=
Microsoft.Practices.Prism.MefExtensions, Version=
DevExpress.Xpf.Core.v16.2, Version=
System.Windows.Forms, Version=
System.Drawing, Version=
Samba.Persistance, Version=
Stateless, Version=
PropertyTools, Version=2012.4.14.1
Samba.Localization, Version=
ReachFramework, Version=
EntityFramework, Version=
FluentValidation, Version=
NCalc, Version=
Microsoft.CSharp, Version=
Omu.ValueInjecter, Version=
Microsoft.Practices.ServiceLocation, Version=
DevExpress.Data.v16.2, Version=
WindowsInput, Version=


[System Info]

Operating System
-Microsoft Windows 10 Home
--CodeSet = 1252
--CSDVersion = 
--CurrentTimeZone = 420
--FreePhysicalMemory = 9310364
--OSArchitecture = 64-bit
--OSLanguage = 2057
--ServicePackMajorVersion = 0
--ServicePackMinorVersion = 0
--Version = 10.0.17134

--Manufacturer = Hewlett-Packard
--Model = HP ENVY 15 Notebook PC
--TotalPhysicalMemory = 17099153408
--UserName = TECHASIA\Stacey


Hey I got your PM sorry was slow respond putting it in forum is always what you should do. It looks like something is wrong with the name of it.

1 Like

I swear we saw this same error not too long ago.

Conversion failed when converting the nvarchar value '40167EECA364_A666_' to data type int.``

My guess is the _ characters are causing it.

Ok so do you have SambaConnect on that computer? For Metrik? From what I read updating SambaConnect to newest version fixes it.

No worries @Jesse , I thought you might be busy :slight_smile:

I did notice this in the error log and was wondering where is it pulling that value from. Looks like a Hexadecimal value and yeah I thought of that too. Its “polluted” by the underlines.

Can you try updating sambaconnect? Just click to install it again and let it upgrade.

I just made a full re-installation of it. Should I try creating the document now?

Yes try now and see if it fixed it.

Unfortunately, it didnt.

Try closing Sambapos restarting it then try. Is it the same error?

Try also removing SambaConnect completely and then try.

That error was created by metrik connect. It should resolve by updating to latest version. But I would try deleting it completely.

Which reminds of :joy:

Wait, Ill go uninstall it and remove all the %appdata% and %programdata% too. Ill let you know soon.

That is a specific error and it has been proven that Sambaconnect is the culprit… specifically an older version. That would explain why it works elsewhere.

Deleting just the SambaPOS Connect and reinstalling it didnt solve it but reinstalling after deleting %appdata% and %programdata% did. Not entirely sure which one of those was keeping the dodgy value.

I guess I can continue with my work as it saved the document properly.

Thanks @Jesse this was really helpful.

1 Like

@Jesse I wanted to ask you but I dont want to open a new topic for this but do you know why is the database that has been wiped of all transactions 900MBs in size? Even if it wipes the transaction from it, does it still keep it somewhere and if so, where?

I think that is more of a Microsoft SQL Question honestly. I will look at some information and get back to you on that.

Remember that it stores a lot of stuff in Database not just transactional data.

Looking at dbo._MigrationHistory table, database was created back in 2015 so it makes sense that it has a lot of stuff inside but almost 900MB of stuff?

I am really curious as to what exactly is it saving and does it make sense in keeping it, because its making it bulky and even when its compressed with the internet speed my client uses its very slow when it comes to syncing it with cloud.