jbailey.spatialbridge

ArcSDE connection timeout .NET

Discussion created by jbailey.spatialbridge on Mar 30, 2014
Latest reply on Apr 3, 2014 by jbailey.spatialbridge
If an invalid value for a connection string is passed to SDEWorkspaceFactory.OpenFromString(), the call hangs:

IWorkspaceFactory workspaceFactory = _workspaceFactory.OpenFromString("InvalidConnectionString", 0);


If I break execution, I can see from the call stack that control is still with the unmanaged code. Unfortunately, this OpenFromString doesn't offer a timeout. What I need to do is, within my .NET managed code, cancel the call to OpenFromString after a certain timeout period. I've tried a couple of approaches, including the following:

Task<IWorkspace> task = new Task<IWorkspace>(() => 
    { 
        return _workspaceFactory.OpenFromString("InvalidConnectionString", 0); 
    });
if (!task.Wait(10000))
{
    throw new TimeoutException();
}
IWorkspace workspace = task.Result;


In this case, task.Wait() always returns false, and task.Result() is always null, even if a valid value for the connection string is passed.

I've also tried the following approach:

IWorkspace workspace = null;
Thread thread = new Thread(() =>
    {
        workspace = _workspaceFactory.OpenFromString("InvalidConnectionString", 0);
    });
thread.Start();
if (!thread.Join(10000))
{
    throw new TimeoutException();
}


In this case, if a valid value for the connection string is passed, execution works as expected, but if an invalid value is passed, the execution still hangs in the unmanaged code, and thread.Join() never returns.

Any suggestions on how to do this?

Outcomes