Select to view content in your preferred language

SQL Error: "Not currently editing a version, cannot stop edit."

1677
7
01-24-2018 07:37 AM
AdelaideZumwalt1
Frequent Contributor

I used this script for a couple months on another database but can't seem to get it to work on the new database. I keep running into the following error: "Not currently editing a version, cannot stop edit." even though my step specifically starts and stops the edit session. What am I missing? The version is being created, I can see it in ArcMap:

EXEC dbo.create_version 'dbo.DEFAULT', 'WMMUpdate', 1, 1, 'This version contains data pushed from WMMExport to ElectricModel';
EXEC dbo.set_current_version 'WMMUpdate';
EXEC dbo.edit_version 'WMMUpdate', 1;

MERGE ElectricModel.dbo.Transformer_evw
USING WMMExport.dbo.TRANSFORMER
ON ElectricModel.dbo.Transformer_evw.GUID_WMM = WMMExport.dbo.TRANSFORMER.wm_ElementGuid
WHEN MATCHED THEN
UPDATE SET ElectricModel.dbo.Transformer_evw.esElementName= WMMExport.dbo.TRANSFORMER.wmElementName;

EXEC dbo.edit_version 'WMMUpdate', 2;

0 Kudos
7 Replies
Asrujit_SenGupta
MVP Regular Contributor

Did you check the Versioned View, if it was updated or not? I tested a similar scenario at my end and observed the error. However, the data did get updated.

This error is observed if I execute all the SQL together. Not if I execute 1 statement at a time...check that.

AdelaideZumwalt1
Frequent Contributor

I checked the versioned view in ArcMap and there were 0 changes. The version doesn't even have a "Modified Date. I ran it as a query and got the error:

 Msg 50000, Level 16, State 1, Procedure edit_version, Line 144
Cannot stop edit on WMMUpdate while version id 20 is the current edit version.

What is version id 20?

"

0 Kudos
Asrujit_SenGupta
MVP Regular Contributor

If you query a versioned view without setting the version and state, you are referencing the current state of the DEFAULT version.

What is a versioned view?—Help | ArcGIS Desktop 

Connect to that version from ArcMap and check for the chenges.

The version doesn't even have a "Modified Date.

This is fine. If you run a Reconcile on that version or make any update using ArcMap, you will see that getting updated.

 Msg 50000, Level 16, State 1, Procedure edit_version, Line 144
Cannot stop edit on WMMUpdate while version id 20 is the current edit version.

This is happening, because another version is set as the current edit version & you are trying to stop editing on WMMUpdate version.

 What is version id 20?

Check the SDE_versions table from the database end..

AdelaideZumwalt1
Frequent Contributor

So I got the scheduled job to run correctly once I created the version and just had sql update it. Although the data was updated correctly, the errors included:

"Not currently editing a version<c/> cannot stop edit. [SQLSTATE 42000] (Error 50000).  The step failed."

It would be nice to get the job to run without these errors so the job history isn't filled with red x's. Any ideas? 

EXEC dbo.set_current_version 'WMMUpdate';
EXEC dbo.edit_version 'WMMUpdate', 1;

MERGE ElectricModel.dbo.Transformer_evw
USING WMMExport.dbo.TRANSFORMER
ON ElectricModel.dbo.Transformer_evw.GUID_WMM = WMMExport.dbo.TRANSFORMER.wm_ElementGuid
WHEN MATCHED THEN
UPDATE SET ElectricModel.dbo.Transformer_evw.esElementName= WMMExport.dbo.TRANSFORMER.wmElementName;


EXEC dbo.edit_version 'WMMUpdate', 2;

0 Kudos
by Anonymous User
Not applicable

We have the same issue with “Not currently editing a version, cannot stop edit.”  after migrating our geodatabase from 10.3 to 10.5 within a SQL Server 2016 database. As an additional issue, EXEC sde.edit_version 'version2edit',1 does not set the editable version as the currect version, so we end up editing the wrong version. We think it has something to do with CONTEXT_INFO which does not return the new values. 

Were you ever able to solve this problem? Your experience would be most welcome.

0 Kudos
Asrujit_SenGupta
MVP Regular Contributor

To set the current version use: 

EXEC sde.set_current_version 'myedits12111';

 Something like this:

EXEC sde.version_util.set_current_version('USER.ABC');

EXEC sde.version_user_ddl.edit_version('USER.ABC',1);

DELETE FROM USER.ABCD_EVW WHERE XXXX = '12345';

COMMIT;
EXEC sde.version_user_ddl.edit_version('USER.ABC',2);

Edit versioned data in SQL Server using SQL—Help | Documentation 

0 Kudos
by Anonymous User
Not applicable

These are indeed the SDE-commands we use. However, after migrating the geodatabase from 10.3 to 10.5, EXEC sde.edit_version 'version2edit',1 does not set the editable version as the currect version. SDE stored procedures SDE_get_globals and SDE_set_globals use the CONTEXT_INFO value, to set the right environment within the script (in which we do the editing). For some reason, CONTEXT_INFO is no longer refreshed immediately, with severe consequences for the integrity of the database. Only, when we run the commands (open edit version, do edits, close edit version) in separate batches, then the CONTEXT_INFO value is passed correctly. I hope this clarified our problem.

0 Kudos