Hi everyone,I have a C# program that runs nightly on 17 layers, going through all records and updating 49 fields with data read from an Oracle table. The problem I am having is that sometimes the program runs successfully and sometimes it does not. On the times that it fails, the code runs to completion without any errors but none of the fields have updated values. Below is the program and I have removed most of the fields so that it could fit in this post without being huge.The very first thing the script does is to check if the layer has locks on it and if it does, the layer is skipped. The next check it populates one field with dummy data and if succeeds, then it goes on to the rest of the code to update all fields.Any idea what the problem might be? I am using ArcMap 9.3.1.Thanks,Carlosprivate static void ProcessLayer(string permitType)
{
IPropertySet pPropertySet = new PropertySetClass();
IWorkspaceFactory pWorkspaceFactory = new SdeWorkspaceFactoryClass();
IFeatureWorkspace pFeatureWorkspace = null;
IFeatureClass pFeatureClass = null;
IDataset pDataset = null;
IWorkspace pWorkspace = null;
IWorkspaceEdit pWorkspaceEdit = null;
ITable pTable = null;
ICursor pCursor = null;
ITrackCancel pTrackCancel = new CancelTrackerClass();
IProgressDialogFactory pProgressDialogFactory = new ProgressDialogFactoryClass();
IProgressDialog2 pProgressDialog2 = null;
IStepProgressor pStepProgressor = null;
OracleConnection dataConnection = new OracleConnection();
OracleCommand dataCommand = new OracleCommand();
OracleDataReader dataReader = null;
try
{
//Get the layer to update.
pPropertySet.SetProperty("SERVER", "gresssde");
pPropertySet.SetProperty("INSTANCE", "5195:rim");
pPropertySet.SetProperty("USER", "rim");
pPropertySet.SetProperty("PASSWORD", "S01stice");
pPropertySet.SetProperty("VERSION", "RIM.DEFAULT");
pFeatureWorkspace = pWorkspaceFactory.Open(pPropertySet, 0) as IFeatureWorkspace;
pFeatureClass = pFeatureWorkspace.OpenFeatureClass(permitType);
pDataset = pFeatureClass as IDataset;
//If layer has locks on it, skip it.
if (HasSchemaLocks(pDataset) == true)
{
string message = "layer " + pDataset.BrowseName + " had locks on it, layer skipped.";
LogMessageToFile(LogsPath + "updatePermitDataAttrDaily_Log_", message);
return;
}
//If layer cannot be attributed, skip it.
if (CanUpdateAttributes(pFeatureClass) == false)
{
string message = "Could not update attributes on layer " + pDataset.BrowseName + ".";
LogMessageToFile(LogsPath + "updatePermitDataAttrDaily_Log_", message);
return;
}
pWorkspace = pDataset.Workspace;
pWorkspaceEdit = pWorkspace as IWorkspaceEdit;
//If permit type field not found, stop code.
if (pFeatureClass.FindField("FEE_PERMIT_TYPE") != -1)
{
//Start an edit session and operation
pWorkspaceEdit.StartEditing(false);
pWorkspaceEdit.StartEditOperation();
pTable = pFeatureClass as ITable;
pCursor = pTable.Update(null, false);
//Get the index numbers for every field being updated.
int permitNoIdx = pCursor.FindField("PERMIT_NO");
int appNoIdx = pCursor.FindField("APP_NO");
int projectNameIdx = pCursor.FindField("PROJECT_NAME");
int appStatusIdx = pCursor.FindField("APP_STATUS");
int activeModIdx = pCursor.FindField("ACTIVE_MOD");
string appNo = string.Empty;
string permitNo = string.Empty;
string projectName = string.Empty;
string appStatus = string.Empty;
string activeMod = string.Empty;
//Set up and open the progress dialog.
int featureCount = 1;
int numberOfFeatures = pFeatureClass.FeatureCount(null);
pProgressDialog2 = pProgressDialogFactory.Create(pTrackCancel, 0) as IProgressDialog2;
pProgressDialog2.CancelEnabled = true;
pProgressDialog2.Description = "Processing Record " + featureCount + " of " + numberOfFeatures;
pProgressDialog2.Title = "Processing...";
pProgressDialog2.Animation = esriProgressAnimationTypes.esriProgressGlobe;
pStepProgressor = pProgressDialog2 as IStepProgressor;
pStepProgressor.MinRange = 0;
pStepProgressor.MaxRange = numberOfFeatures;
pStepProgressor.StepValue = 1;
pStepProgressor.Message = permitType;
pProgressDialog2.ShowDialog();
bool canContinue = true;
//Read values from Oracle and update each feature with the info.
dataConnection.ConnectionString = "Data Source=genp;" +
"Persist Security Info=True;" +
"User ID=pub;" +
"Password=pub;" +
"Unicode=True";
dataConnection.Open();
dataCommand.Connection = dataConnection;
IRow pRow = pCursor.NextRow();
while (pRow != null)
{
appNo = pRow.get_Value(appNoIdx).ToString();
dataCommand.CommandText = "SELECT PERMIT_NO, PROJECT_NAME, APP_STATUS, ACTIVE_MOD, " +
"FROM REG.REG_GIS WHERE app_no = '" + appNo + "'";
dataReader = dataCommand.ExecuteReader();
while (dataReader.Read())
{
if (!dataReader.IsDBNull(0))
{
permitNo = dataReader.GetString(0);
permitNo = permitNo.Replace("'", "");
}
if (!dataReader.IsDBNull(1))
{
projectName = dataReader.GetString(1);
projectName = projectName.Replace("'", "");
}
if (!dataReader.IsDBNull(2))
{
appStatus = dataReader.GetString(2);
appStatus = appStatus.Replace("'", "");
}
if (!dataReader.IsDBNull(3))
{
activeMod = dataReader.GetString(3);
activeMod = activeMod.Replace("'", "");
}
if (permitNoIdx != -1) pRow.set_Value(permitNoIdx, permitNo);
if (projectNameIdx != -1) pRow.set_Value(projectNameIdx, projectName);
if (appStatusIdx != -1) pRow.set_Value(appStatusIdx, appStatus);
if (activeModIdx != -1) pRow.set_Value(activeModIdx, activeMod);
pCursor.UpdateRow(pRow);
}
dataReader.Close();
dataReader.Dispose();
pRow = pCursor.NextRow();
//Increment the progress dialog.
canContinue = pTrackCancel.Continue();
if (canContinue == true)
{
pStepProgressor.Step();
featureCount++;
pProgressDialog2.Description = "Processing Record " + featureCount + " of " + numberOfFeatures;
}
else
{
pProgressDialog2.HideDialog();
return;
}
//Clear values.
appNo = string.Empty;
permitNo = string.Empty;
projectName = string.Empty;
appStatus = string.Empty;
activeMod = string.Empty;
}
//Stop editing
pWorkspaceEdit.StopEditOperation();
pWorkspaceEdit.StopEditing(true);
//Close progress dialog.
pProgressDialog2.HideDialog();
} //if (pFeatureClass.FindField("FEE_PERMIT_TYPE") != -1)
}
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace + "\r\n" + ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}