How to edit feature in sqlserver geodatabase

المشرف العام

Administrator
طاقم الإدارة
I am using arcmap 10.2.1 and arcobject 10.2.1,I just want to conncet to a geodatabase and edit,add,delete a feature from a feature class using arcobject,I tried to connect to database and it works fine but I cant start edit and add a feature to it,here is my code

public void open_Workspace() { Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SqlWorkspaceFactory"); IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType); IWorkspaceFactory2 workspaceFactory2 = workspaceFactory as IWorkspaceFactory2; // Build a connection string. String[] connectionProps = { "dbclient=SQLServer", "serverinstance=CRAZYVIRUS-HP", "database=land_gis", "authentication_mode=OSA" }; String connString = String.Join(";", connectionProps); IWorkspace workspace = workspaceFactory2.OpenFromString(connString, 0); ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explict Cast ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("DBO.test"); ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = new ESRI.ArcGIS.Carto.FeatureLayerClass(); featureLayer.FeatureClass = featureClass; featureLayer.Name = featureClass.AliasName; featureLayer.Visible = true; IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace; IWorkspaceEdit2 workspaceEdit2 = (IWorkspaceEdit2)workspaceEdit; IMultiuserWorkspaceEdit muWorkspaceEdit = (IMultiuserWorkspaceEdit)workspace; Make sure that non-versioned editing is supported. If not, throw an exception. if (!muWorkspaceEdit.SupportsMultiuserEditSessionMode (esriMultiuserEditSessionMode.esriMESMNonVersioned)) { throw new ArgumentException( "The workspace does not support non-versioned editing."); } // Start a non-versioned edit session. muWorkspaceEdit.StartMultiuserEditing (esriMultiuserEditSessionMode.esriMESMNonVersioned); featureClass.CreateFeature(); // Stop the edit session. The saveEdits parameter indicates the edit session // will be committed. workspaceEdit.StopEditing(true);}when I run above code I got this error Unable to cast COM object of type 'System.__ComObject' to interface type 'ESRI.ArcGIS.Geodatabase.IWorkspaceEdit2'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{199A1F9D-435A-4118-9B3F-4E0B8F984AA0}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

I tried to enable versionning or disable it but there isnot any chance to make it work..Can you help me find the soluton into this error?Is there any thing wrong with my connection?



أكثر...
 
أعلى