Select to view content in your preferred language

GetConnectionString error when a Joined table present

1108
8
Jump to solution
04-12-2019 07:18 AM
BrianBulla
Honored Contributor

Hi,

I'm using the following line of code to get the ConnectionString info on a FeatureClass.  Usually there are no problems, but when I join a table to the layer, I get a "Data Store is invalid or not supported" error.  Any ideas as to why this might be happening??  The joined table is a .xls spreadsheet.

0 Kudos
1 Solution

Accepted Solutions
RichRuh
Esri Regular Contributor

Hi Brian,

A join itself is not editable, so your IsEditable() check shouldn't be needed.  However, you *can* edit the individual tables that make up the join.  If there is another layer with the source tables, you'll catch it that way.  If you're concerned about a user programmatically editing the source tables, keep reading...

I said earlier today that there isn't a way to get the Join from a table.  That is incorrect.  If Table.IsJoinedTable() returns true, you can use Table.GetJoin() to get the Join.  Then Join.GetOriginTable() and Join.GetDestinationTable() can give you the individual tables that make up the join.

Putting all of this together should give you a foolproof solution. 

--Rich

View solution in original post

8 Replies
RichRuh
Esri Regular Contributor

If I understand this correctly, the feature layer refers to a join between an excel file and another datastore, correct?  In this case, there is no actual datastore for the layer, since the join is computed in-memory.

0 Kudos
BrianBulla
Honored Contributor

Hi Rich,

Basically what I am doing is parsing the Connection String to see if the current layer is versioned.  Is there a better way of doing this (ie. figuring out if a layer is versioned or not)??

0 Kudos
RichRuh
Esri Regular Contributor

If the layer has a valid Datastore, and if the Datastore is of type Geodatabase, you can call Geodatabase.IsVersioningSupported()

0 Kudos
BrianBulla
Honored Contributor

Hi Rich,

So is it any type of Join that will cause the 'Datastore' to be invalid??  I have also tried with a join to a FGDB table, and still get the same error - Datastore is invalid.

Is there a way to determine if a layer with a join is Versioned??

Basically I'm creating a tool to 'watch' for edits on layers as they happen (ie. RowChangedEvent, etc.).  But I only need to watch for edits on valid layers, which are layers in our Corporate SDE....so Versioned layers.  I figured checking to see if the layer is Versioned would be the easiest way of doing this, but when joins are present things don't work although edits could still be happening.

Any ideas on the best work-around for this??

0 Kudos
RichRuh
Esri Regular Contributor

Any join where the source tables come from different data stores takes place on the client, and the Datastore is invalid.

If you had access to the Join itself, you can get the origin and destination tables, but if you're coming directly from the layer the only thing you'll have is the JoinedTable.  I don't know of a way to go from the JoinedTable to the Join.

The only workaround I can suggest is to listen to events from SDE tables *and* joins (i.e., tables without a valid datastore).  This may mean listening to more events than you have to.

I hope this helps,

--Rich

BrianBulla
Honored Contributor

Hi Rich,

Well I've found a compromise that pretty much works, although not perfectly.  Doing this....

 //This checks to make sure the layer is Versioned
        private bool IsVersioned(FeatureLayer fLayer)
        {
            try
            {
                //Use this to avoid errors on Joined Tables...not really checking if Versioned, but the next best thing
                if (fLayer.GetTable().IsJoinedTable())
                {
                    if (fLayer.IsEditable)
                        return true;
                    else
                        return false;
                }
                    
                Geodatabase theGDB = (Geodatabase)fLayer.GetFeatureClass().GetDatastore();
                if (theGDB.IsVersioningSupported())
                {
                    //MessageBox.Show("Yes, versioning supported for " + fLayer.URI);
                    return true;
                }                
                
                return false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error in 'IsVersioned' procedure:");
                return false;
            }                        
        }

...seems to work.  In our situation the worse that will happen is some fields in a joined shapefile or PGDB might also get flagged as 'Versioned', but it's not a huge problem.  At least the SDE Feature Classes with joins will still get picked up.

0 Kudos
RichRuh
Esri Regular Contributor

Hi Brian,

A join itself is not editable, so your IsEditable() check shouldn't be needed.  However, you *can* edit the individual tables that make up the join.  If there is another layer with the source tables, you'll catch it that way.  If you're concerned about a user programmatically editing the source tables, keep reading...

I said earlier today that there isn't a way to get the Join from a table.  That is incorrect.  If Table.IsJoinedTable() returns true, you can use Table.GetJoin() to get the Join.  Then Join.GetOriginTable() and Join.GetDestinationTable() can give you the individual tables that make up the join.

Putting all of this together should give you a foolproof solution. 

--Rich

BrianBulla
Honored Contributor

Nice!!  Here is the final code:

        //This checks to make sure the layer is Versioned
        private bool IsVersioned(FeatureLayer fLayer)
        {
            try
            {
                //Use this to avoid errors on Layers with Joined Tables
                if (fLayer.GetTable().IsJoinedTable())
                {
                    Join theJoin = fLayer.GetTable().GetJoin();
                    Table theTable = theJoin.GetOriginTable();

                    Geodatabase tableGDB = (Geodatabase)theTable.GetDatastore();
                    if (tableGDB.IsVersioningSupported())
                        return true;
                    else
                        return false;                    
                }
                    
                Geodatabase theGDB = (Geodatabase)fLayer.GetFeatureClass().GetDatastore();
                if (theGDB.IsVersioningSupported())
                {
                    //MessageBox.Show("Yes, versioning supported for " + fLayer.URI);
                    return true;
                }                    

                return false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error in 'IsVersioned' procedure:");
                return false;
            }                        
        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thanks for your help!