I have some tables included in a dataset that are used for lookups. I have foreign key constraints on some of the child tables that reference these tables. My problem is that when I have finished buiding the dataset I do a .WriteXML and then FTP that outut to a mainframe and some of the lookup tables I want to remove are big, and the mainframe doesn't need them.
I have been able to remove what I think are all the relationships and constraints associated with these tables but when I run the program and call StorageChangeEnd, an exception is thrown saying "Property not accessible because 'Cannot have a relationship between tables in different DataSets.'.".
I don't know where to look because the message gives no indication as to the name of the offending relationship or the table. Following is a code snippet:
dsProfile.StorageChangeBegin()
With dsProfile.StorageDataSet
.EnforceConstraints = False
.Tables("tblProfileSourceCodes").Constraints.Clear()
.Tables("tblProfileSourceTypes").Constraints.Clear()
.Tables("tblProfilePPISegment").Constraints.Clear()
.Tables("tblProfileFloatSegment").Constraints.Clear()
.Tables("tblProfileProcessTimeSlot").Constraints.Clear()
.Tables("tblProfileDepositTimeSlot").Constraints.Clear()
.Tables("tblProfileProducts").Constraints.Clear()
.Tables("tblProfileSourceCodes").ParentRelations.Remove("tblProductionSourceCodes - tblProfileScourceCodes")
.Tables("tblProfileSourceTypes").ParentRelations.Remove("tblProductionSourceTypes - tblProfileSourceTypes")
.Tables("tblProfilePPISegment").ParentRelations.Remove("tblProductionSegment - tblProfilePPISegment")
.Tables("tblProfileFloatSegment").ParentRelations.Remove("tblProductionSegment - tblProfileFloatSegment")
.Tables("tblProfileProducts").ParentRelations.Remove("tblProductinProducts - tblProfileProducts")
RemoveTable(dsProfile.StorageDataSet, "tblProductionSourceCodes")
RemoveTable(dsProfile.StorageDataSet, "tblProductionSourceTypes")
RemoveTable(dsProfile.StorageDataSet, "tblProductionProducts")
RemoveTable(dsProfile.StorageDataSet, "tblProductionSegment")
Dim i As Integer = .Relations.Count - 1
While i >= 0
If .Relations.Item(i).RelationName.StartsWith("tblProducti") Then
.Relations.Remove(.Relations.Item(i).RelationName)
End If i -= 1
End While
'.Relations.Remove("tblProductionBank - tblProfileProcessTimeSlot")
'.Relations.Remove("tblProductionBank - tblProfileDepositTimeSlot")
'RemoveTable(dsProfile.StorageDataSet, "tblProductionBank")
End With
'---------------------------------------------------
' Now tell the C1DataSet we're finished changing the
' underlying storage
'---------------------------------------------------
dsProfile.StorageChanged(
True)dsProfile.StorageChangeEnd()
dsProfile.WriteXml(sPath & sFileName)
Private Sub RemoveTable(ByVal ds As DataSet, ByVal tblName As String)With ds
.Tables(tblName).ChildRelations.Clear()
.Tables(tblName).Constraints.Clear()
.Tables(tblName).ParentRelations.Clear()
.Tables.Remove(tblName)
End With
End Sub