Print Page | Close Window

Best way to detect loss of connection?

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1678
Printed Date: 18-May-2025 at 3:15am


Topic: Best way to detect loss of connection?
Posted By: chuckc
Subject: Best way to detect loss of connection?
Date Posted: 10-Mar-2010 at 1:57pm
What's the recommended way to detect absence or loss of a data connection?

I see a number of examples in the documentation dealing with saving and restoring cache contents, but they are all driven by user actions. I'd like to recognize at application start-up that a database connection is not available and immediately restore from a saved cache file. I'd also like to recognized when a connection has been lost during a session, and save cache contents to disk at that time.

Thanks!



Replies:
Posted By: davidklitzke
Date Posted: 11-Mar-2010 at 9:19am
To determine whether you can immediately connect to a database use this EntityManager constructor:
 
Syntax
Visual Basic (Declaration)  
Public Function New( _
   ByVal shouldConnect As Boolean _
)
 
Visual Basic (Usage) Copy Code
Dim shouldConnect As Boolean
 
Dim instance As EntityManager(shouldConnect)
 
C#  
public EntityManager(
   bool shouldConnect
)
 
Parameters
shouldConnect
True if a connection to the EntityServer should be made.
Exceptions
Exception Description
IdeaBlade.Core.IdeaBladeException Thrown for miscellaneous initialization failures
EntityServerException Thrown for connection failures
ArgumentException Thrown in a Silverlight application when BOS is not specified
 
Once you have created an EntityManager, you can check the IsConnected property of the EntityManager:
 
 IsConnected                                             Returns whether the EntityManager is currently connected to an EntityServer.
 



Print Page | Close Window