ArcGIS Enterprise StartMultiuserEditing returns Workspace or data source is read only.

529
6
09-13-2023 09:54 AM
SivaNagarajan
New Contributor

Hello Experts,

I'm new to ArcGIS Pro and ArcGIS Enterprise SDK. I'm creating an editing tool in ArcGIS Pro. I'm facing "Workspace or data source is read only" error while trying to start edit. Here is details about the issue.

I'm using ArcSDE and connected through connection properties. But when I try to start editing it returns the error.

var config = Properties.Settings.Default;

IPropertySet propertySet = new PropertySet();
propertySet.SetProperty("Database", config.SDE_Database);
propertySet.SetProperty("INSTANCE", "sde:sqlserver:" + config.SDE_Server);
propertySet.SetProperty("USER", config.SDE_UserName);
propertySet.SetProperty("PASSWORD", config.SDE_Password);
propertySet.SetProperty("VERSION", config.SDE_Version);
return propertySet;

var workspace = GetWorkspace();
return (IFeatureWorkspace)workspace;[

_workspaceEdit = (IWorkspaceEdit)featureWorkspace;

IMultiuserWorkspaceEdit muWorkspaceEdit = (IMultiuserWorkspaceEdit)featureWorkspace;
muWorkspaceEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned);


_workspaceEdit.StartEditOperation();

0 Kudos
6 Replies
RichRuh
Esri Regular Contributor

Siva,

This looks like ArcObjects code designed for ArcMap.  ArcGIS Pro has a completely different API.  The documentation home page is here.

--Rich

0 Kudos
SivaNagarajan
New Contributor

@RichRuh, thanks for the details. Here, I want to provide more information to explain the problem.

ArcGIS Pro version: 3.1
Enterprise Geodatabase version: 11.1
ArcGIS Enterprise SDK version: 11.1
MS SQL Server version: 2022 Express

Even though I am working on an ArcGIS Pro Add-in project, I am performing extensive editing work on the Enterprise Geodatabase . The feature classes and tables in the Enterprise Geodatabase are not available as layers on the ArcPro map. Therefore, I have another class library reference project that uses the ArcGIS Enterprise SDK (the latest version of ArcObjects) to connect to the Enterprise Geodatabase and perform the editing work.

My Enterprise SDK code for editing and updating the feature class in a File Geodatabase (FileGDBWorkspaceFactory) is working perfectly. Also, when I attempt to connect to and edit the Enterprise Geodatabase (SdeWorkspaceFactory), the connection works well, and I can read the Enterprise Geodatabase's feature class records without any issues. However, the problem arises only when I try to execute the "StartEditing" operation, as it results in a "Workspace or data source is read-only" error.

I have thoroughly examined all possible causes for this issue and have ensured the following:

1. The database connection has write access; I used the same connection properties and attempted to edit the Enterprise Geodatabase directly in ArcPro, and I was able to make edits.
2. I have tried different Enterprise Geodatabases, including MS SQL Server and PostgreSQL, and different versions, including 10.7 and 11.1.
3. I have tested with an Enterprise Geodatabase connection on both a remote machine and a local machine.

Therefore, I suspect that I may be overlooking something related to enabling write-mode (making it not read-only) either within the Enterprise Geodatabase settings or during Workspace creation. Once this issue is resolved, I can use the same code that worked for the File Geodatabase connection with the Enterprise Geodatabase.

Here is the code I am using to connect to and edit the Enterprise Geodatabase:

// Set up the workspace factory for SQL Server with Database Authentication.
IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactoryClass();

// Set the connection properties.
IPropertySet propertySet = new PropertySetClass();
propertySet.SetProperty("DATABASE", "_db_name_");
propertySet.SetProperty("INSTANCE", "sde:sqlserver:" + "_instance_");
propertySet.SetProperty("USER", "_user_");
propertySet.SetProperty("PASSWORD", "_password_");
propertySet.SetProperty("AUTHENTICATION_MODE", "DBMS");
propertySet.SetProperty("VERSION", "dbo.DEFAULT");

IWorkspaceEdit workspaceEdit = null;

try
{
    // Open the connection.
    IWorkspace workspace = workspaceFactory.Open(propertySet, 0);

    if (workspace != null)
    {
        // Check if the workspace supports editing.
        workspaceEdit = (IWorkspaceEdit)workspace;
        if (!workspaceEdit.IsBeingEdited())
        {
            // Start an edit session.
            workspaceEdit.StartEditing(true); //<<<<<< THIS IS WHERE I AM GETTING THE READ-ONLY ERROR >>>>>>>
            workspaceEdit.StartEditOperation();
        }

        // Open the feature class you want to edit.
        IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
        IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("_feature_class_");

        // Create a query filter to find the specific feature to edit.
        IQueryFilter queryFilter = new QueryFilterClass();
        queryFilter.WhereClause = "YourField = 'YourValue'"; // Modify to match your criteria

        // Search for the feature.
        IFeatureCursor featureCursor = featureClass.Search(queryFilter, true);
        IFeature feature = featureCursor.NextFeature();

        if (feature != null)
        {
            // Modify the attributes of the feature as needed.
            feature.set_Value(featureClass.Fields.FindField("AttributeFieldName"), "NewValue");

            // Save the changes.
            feature.Store();
            workspaceEdit.StopEditOperation();
            workspaceEdit.StopEditing(true);

            Console.WriteLine("Feature edited successfully.");
        }
        else
        {
            Console.WriteLine("Feature not found.");
        }

        // Release resources.
        Marshal.ReleaseComObject(featureCursor);
        Marshal.ReleaseComObject(workspace);
    }
    else
    {
        Console.WriteLine("Failed to connect to the geodatabase.");
    }
}
catch (Exception ex)
{
    Console.WriteLine("Error: " + ex.Message);
}
finally
{
    // Make sure to stop the edit session in the finally block to release locks.
    if (workspaceEdit != null && workspaceEdit.IsBeingEdited())
    {
        workspaceEdit.StopEditOperation();
        workspaceEdit.StopEditing(true);
    }
}

I am getting the ErrorCode: -2147220893, ErrorMessage: "Workspace or data source is read only" at line number 27 while calling StartEditing on the worksapce.

Thank you again and looking for your advice and directions.

0 Kudos
RichRuh
Esri Regular Contributor

Siva,

The Pro SDK is perfectly capable of working with Enterprise geodatabases, regardless of whether or not the tables and feature classes are in the map.  You can start reading here to see how to connect.

The Enterprise SDK is designed to build server-side extensions. Using it on the desktop is not supported and extremely unlikely to work.

--Rich

 

0 Kudos
Vasu80
by
New Contributor

I am working with Siva (the author of this post) and as you suggested I tried ArcGIS Pro SDK to edit the Enterprise Geodatabase record.

I am using the below code to edit the feature:

// Create an edit operation
var editOperation = new ArcGIS.Desktop.Editing.EditOperation();
editOperation.Modify(feature, fieldIndex, fieldValue);

// Execute the edit operation to save the changes
var result = editOperation.Execute();
if (result != true)
{
    MessageBox.Show("Edit Error:" + editOperation.ErrorMessage);
}

I am getting the "Edit operation failed." error all the time. I can't find what is the actual cause of this error. 

I copied the same feature class into a File Geodatabase and changed the ArcGIS Pro SDK code to connect with the File Geodatabase. There it is working perfectly and I can see the updates in the feature class.

It looks like the Enterprise Geodatabase EDIT is not working from my ArcGIS Pro environment programmatically.

Advise what else I can try to troubleshoot this edit failure.

0 Kudos
RichRuh
Esri Regular Contributor

First, I assume that __user__ has read/write access to the default version, right?  A great way to verify this is try to make an identical edit using the ArcGIS Pro user interface.

Another thing to try would be to use the low-level geodatabase routines- using Geodatabase.ApplyEdits, etc.  Not good for a production app- for example, you'd have no undo/redo, but the error messages might be better.

--Rich

0 Kudos
sjones_esriau
Esri Contributor

You can also examine the EditOperation.ErrorMessage property for more information if it is a known error.

0 Kudos