Select to view content in your preferred language

How to know when the connection to SQL server was lost?

504
0
01-04-2011 03:24 AM
RoyDallal
Emerging Contributor
Hi,
Yesterday we had a problem with the DB (SQL Server 2008) and it was restarted.
Our application didn't work until we restarted it as well.

I found IWorkspaceFactoryStatus and tried to use it to find the status of my IWorkspace and in the Immediate Window in VS2010 it works and shows that (after restarting the SQL service) the status is esriWCSAvailable. But when running the code in debug I get esriWCSUp and then when running:
       featureClass.Search(queryFilter, true);
I get the exception:
Failure to access the DBMS server [Microsoft SQL Server Native Client 10.0: Deferred prepare could not be completed.] [sde.sde.GDB_Items]

The code I use to check the IWorkspace status is:
        private bool IsWorkspaceRunning(IWorkspace workspace)
        {
            IWorkspaceFactoryStatus workspaceFactory = new SdeWorkspaceFactoryClass();
            return workspaceFactory.PingWorkspaceStatus(workspace).ConnectionStatus ==
                   esriWorkspaceConnectionStatus.esriWCSUp;
        }

I am running it with ArcEngine (in coded Unit tests).

Can anyone help me?
Roy Dallal
0 Kudos
0 Replies