ArcSDEWorkspace Factory

844
3
11-04-2011 10:37 AM
MakindeFalade
New Contributor
I am relatively new to ArcObjects or I should say I haven't done this in a while.  I am trying to edit an sde table within a Map document but can't seem to find any examples of how to do this the way i want.  Basically, i have reference to the table in the map document via the IActiveView ITableCollection interface.  I need to edit/create rows to the table.  I need help in starting an edit session without having to specify IpropertySet properties.  I guess what I am driving at is to be able to somehow know the SdeWorkspaceFactory from the table in the map document.  I have tried creating the SdeWorkspaceFactory but keep getting "Sde not running on Server" error. 


I would like something like these rather than what i have below.

ITableCollection tableCollection = activeView as ITableCollection;
ITable mappingTable = tableCollection.get_Table(0);

IWorkspace wkspc = mappingTable.workspace // IS IT SOMEHOW POSSIBLE TO GET THE WORKSPACE FROM THE TABLE OR LAYER/FEATURECLASS?


---------------------------------------------------------
THIS IS WHAT I CURRENTLY HAVE







Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory");
            IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);


            // Create a property set and populate it with connection properties.
            IPropertySet propertySet = new PropertySetClass();
            propertySet.SetProperty("SERVER", System.Configuration.ConfigurationSettings.AppSettings["SERVER"]);
            propertySet.SetProperty("INSTANCE", System.Configuration.ConfigurationSettings.AppSettings["INSTANCE"]);
            propertySet.SetProperty("DATABASE", System.Configuration.ConfigurationSettings.AppSettings["DATABASE"]);
            propertySet.SetProperty("USER", System.Configuration.ConfigurationSettings.AppSettings["USER"]);
            propertySet.SetProperty("PASSWORD", System.Configuration.ConfigurationSettings.AppSettings["PASSWORD"]);
            propertySet.SetProperty("VERSION", System.Configuration.ConfigurationSettings.AppSettings["VERSION"]);
           
            string msg = "";
            IWorkspace workspace = null;
            IWorkspaceEdit workspaceEdit = null;
            try
            {
                // Open the geodatabase using the property set.
                workspace = workspaceFactory.Open(propertySet, 0); // BTW I KEEP GETTING TETH "SDE NOT RUNNING ON SERVER ERROR" here.


IMultiuserWorkspaceEdit and IWorkspaceEdit2 interfaces.
                IMultiuserWorkspaceEdit muWorkspaceEdit = workspace as IMultiuserWorkspaceEdit;
                workspaceEdit = workspace as IWorkspaceEdit;

                // Start a versioned edit session and an edit operation.
                muWorkspaceEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned);
                workspaceEdit.StartEditOperation();
            }
            catch (COMException comExc1)
            {
                msg = comExc1.Message;
            }
0 Kudos
3 Replies
RichardFairhurst
MVP Honored Contributor
Here are the crucial interfaces and code to derive the SDE connection of a Feature Class (I believe it should also work for a table if you assign the Table from the IStandaloneTable to the Dataset) to set up SDE editing without knowing the connection properties (Code is VBA, but basically the same as VB.Net if the Set keywords are removed):

  Dim pDataset As IDataset
  Dim pWorkspace As IWorkspace ' Added interface to set up SDE editing
  Dim pFeatureWorkspace As IFeatureWorkspace ' Added interface to set up SDE editing
  Dim pWorkspaceEdit As IWorkspaceEdit ' Added interface to set up SDE editing
  Dim pAnnoLayer As IAnnotationLayer
  ' Assume I have a valid Annotation layer assigned to the pLayer variable
  Set pAnnoLayer = pLayer
  Set pDataset = pAnnoLayer  ' the SDE layer from the map.
  '*********************************
  ' Verify Workspace is in an Edit state
  '*********************************
  Set pWorkspace = pDataset.Workspace
  Set pFeatureWorkspace = pWorkspace
  Set pWorkspaceEdit = pFeatureWorkspace
  If pWorkspaceEdit.IsBeingEdited Then
    pWorkspaceEdit.EnableUndoRedo
    pWorkspaceEdit.StartEditOperation ' Editing Started
      ' Do your edits here
    pWorkspaceEdit.StopEditOperation ' Editing completed
  End If
0 Kudos
NeilClemmons
Regular Contributor III
If the table is in the map then the database connection is already opened.  Just get the workspace from the table and start your edit session.  You can use IWorkspaceEdit or use IEditor.

Remember, standalone table and tables are not the same thing so make sure you get the reference to the table correctly.

Dim tableCollection As IStandAloneTableCollection = map
Dim standAloneTable As IStandAloneTable = tableCollection.StandAloneTable(indexOfYourTable)
Dim table As ITable = standAloneTable.Table
Dim dataset As IDataset = table
Dim workspace As IWorkspace = dataset.Workspace

' use IWorkspaceEdit
Dim workspaceEdit As IWorkspaceEdit = workspace
workspaceEdit.StartEditing(false)

' use IEditor
Dim editor As IEditor = GetEditorExtension()
editor.StartEditing(workspace)
0 Kudos
MakindeFalade
New Contributor
Thank you very much that was most helpful. Just what I needed
0 Kudos