Hi, there,
I am investigating an error (could be one message from two possible messages in the log file) in this method - ConnectWorkspace().
1) error message 1: "Unable to cast SdeWorkspaceFactoryClass to IWorkspaceFactoryStatus
OR
2) error message 2: “The server threw an exception. (Exception from ... (RPC_E_SERVERFAULT))”
It works in a windows service every minute. It seems to be failed after SDE compress. SDE compress executes every night. But the method fails every other week.
Questions:
1) What line in the code below throws error message 2?
1a) After error message 2 each run of that method creates an additional connection to SDE as a result of that a "Maximum Number of Connections ..." error appears after some time (hours).
2) How you explain the code in the line:
IWorkspaceFactoryStatus pWorkspaceFactoryStatus = new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactoryClass();
I have no idea why it works and doesn't fail at the first time?
3) Could it be some how linked to memory leaks in the service (I see they exist. I use Red Gate ANTS Memory Profiler)?
4) How to reproduce that errors? I cannot reproduce it in a simple winform using classes from that winservice? Is there any difference how I run the method ConnectWorkspace() and how it runs in the service?
Thanks for any ideas.
///////////////////////////////////////////////////////////////////////////////////////////////////////////
private static bool ConnectWorkspace(ref IWorkspace pWorkspace)
{
try
{
if (pWorkspace == null)
{
//**This is when the application starts.
pWorkspace = null;
QAModFun.OpenSDEFromFile(mSDEFlNm, out pWorkspace);
return true;
}
//**This will happen, after compress the connection is lost, hence the connection needs to be pinged, and
//**when the status is 'UP' then opening the available connection, and the reconnecting.
IWorkspaceFactoryStatus pWorkspaceFactoryStatus = new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactoryClass();
IEnumWorkspaceStatus pEnumWorkspaceStatus = pWorkspaceFactoryStatus.WorkspaceStatus;
IWorkspaceStatus pWorkspaceStatus = pEnumWorkspaceStatus.Next();
bool blnConnected = false;
if (pWorkspaceStatus != null)
{
blnConnected = true;
while (pWorkspaceStatus != null && blnConnected == true)
{
if (pWorkspaceStatus.ConnectionStatus != esriWorkspaceConnectionStatus.esriWCSUp)
blnConnected = false;
pWorkspaceStatus = pEnumWorkspaceStatus.Next();
}
}
if (blnConnected == false)
{
//**Ping the workspace and if 'UP' reconnect.
pWorkspaceStatus = pWorkspaceFactoryStatus.PingWorkspaceStatus(pWorkspaceDef);
if (pWorkspaceStatus.ConnectionStatus == esriWorkspaceConnectionStatus.esriWCSAvailable)
{
pWorkspaceDef = pWorkspaceFactoryStatus.OpenAvailableWorkspace(pWorkspaceStatus);
pWorkspaceDef = null;
QAModFun.OpenSDEFromFile(mSDEFlNm, out pWorkspaceDef);
}
}
return true;
}
catch (Exception ex)
{
WriteToLogFile(ex);
return false;
}
}
1a) After error message 2, each run of that method creates an additional connection to SDE as a result of that a "Maximum Number of Connections ..." error appears after some time (hours).