I am migrating an existing Windows application that uses ArcObjects 10.* to the new version ArcGIS 11.1. I found I have to migrate the existing ArcObjects SDK code to ArcGIS Enterprise SDK in the new version to work with the File and Enterprise Geodatabases.
I migrated all the code to ArcGIS Enterprise SDK and it is working perfectly when connecting and editing a File Geodatabase. But If I try to edit an Enterprise Geodatabase (formerly ArcSDE Geodatabase), I can read it, but unable to edit it. While calling the `IWorkspaceEdit.StartEditing` (line 27 in the below code) it throws ErrorCode: -2147220893, ErrorMessage: "Workspace or data source is read only". But the same code was working before with ArcObjecs to edit ArcSDE.
I have thoroughly examined all possible causes for this issue and have ensured the following:
- 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.
- I have tried different Enterprise Geodatabases, including MS SQL Server and PostgreSQL, and different versions, including 10.7 and 11.1.
- 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);
}
}
Please advise how can I resolve the workspace read-only issue and resolve this problem.
Are there any special settings I have to do in ArcGIS Enterprise to get this editing work?
Thank you for your time.