Where can we find the last inserted key of a table in the Microsoft SQL server database

0
We have added content to a Mendix table using a SQL script. When we then adding a new item using the Mendix application we get a duplicate key error. It seems that somewhere in the database the last inserted index on that table is stored.  Can you tell me where we can find this index? Error description: An error has occurred while handling the request. [User 'MxAdmin' with session id '0faaa92f-7e73-410b-b7fe-155d52a2459c' and roles 'MxAdministrator']   --------   com.mendix.core.CoreRuntimeException: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: com.mendix.core.CoreRuntimeException: Exception occurred in action '{"before":[{}],"action":{"type":"CommitAction"},"after":[],"type":"EventExtendedAction"}', all database changes executed by this action were rolled back                 at com.mendix.core.actionmanagement.ActionManager.executeInTransactionSync(ActionManager.java:143)   Caused by: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: com.mendix.core.CoreRuntimeException: Exception occurred in action '{"before":[{}],"action":{"type":"CommitAction"},"after":[],"type":"EventExtendedAction"}', all database changes executed by this action were rolled back                 at com.mendix.core.actionmanagement.ActionManager.executeSync(ActionManager.java:176)   Caused by: com.mendix.systemwideinterfaces.MendixRuntimeException: com.mendix.core.CoreRuntimeException: Exception occurred in action '{"before":[{}],"action":{"type":"CommitAction"},"after":[],"type":"EventExtendedAction"}', all database changes executed by this action were rolled back                 at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:40)   Caused by: com.mendix.core.CoreRuntimeException: Exception occurred in action '{"before":[{}],"action":{"type":"CommitAction"},"after":[],"type":"EventExtendedAction"}', all database changes executed by this action were rolled back                 at com.mendix.core.actionmanagement.CoreAction.processErrorState(CoreAction.java:303)   Caused by: com.mendix.core.CoreException: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: com.mendix.systemwideinterfaces.connectionbus.ConnectionBusException: Exception occurred while inserting data. (SQL State: 23000, Error Code: 2627)                 at com.mendix.core.actionmanagement.SyncEventExtendedAction.executeAction(SyncEventExtendedAction.java:39)   Caused by: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: com.mendix.systemwideinterfaces.connectionbus.ConnectionBusException: Exception occurred while inserting data. (SQL State: 23000, Error Code: 2627)                 at com.mendix.core.actionmanagement.ActionManager.executeSync(ActionManager.java:176)   Caused by: com.mendix.systemwideinterfaces.MendixRuntimeException: com.mendix.systemwideinterfaces.connectionbus.ConnectionBusException: Exception occurred while inserting data. (SQL State: 23000, Error Code: 2627)                 at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:40)   Caused by: com.mendix.systemwideinterfaces.connectionbus.ConnectionBusException: Exception occurred while inserting data. (SQL State: 23000, Error Code: 2627)                 at com.mendix.connectionbus.connections.jdbc.JDBCDataStore.getCorrectException(JDBCDataStore.java:1186)   Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Violation of PRIMARY KEY constraint 'PK__saf$harb__3213E83F18AD54BE'. Cannot insert duplicate key in object 'dbo.saf$harbors'. The duplicate key value is (162692536538759572).                 at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:217)                 at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1635)
asked
2 answers
1

Not answering your question. But related; imho never add data to the (Mendix) database using a SQL script bypassing the Mendix runtime. The Mendix platform is designed in such way that the Mendix runtime is in control of the ID's references etc. Bypassing this with a SQL script will almost by definition cause these kind of errors. 

 

So my suggestion is not to hack around this issue, but execute the import via the Mendix runtime.

answered
0

If for whatever reason you need to directly store data in the database make sure to create the records in Mx and then update the records in the SQL import making sure the Id's are correct. 

answered