I've got a WPF application that uses LINQ to SQL DataContexts. The first call to the database would be from the ObjectDataProvider in the XAML of the main form:
<ObjectDataProvider x:Key="WaitingPatientDS" ObjectType="{x:Type local:clsPatients}">
<ObjectDataProvider.ConstructorParameters>
<sys:Boolean>True</sys:Boolean>
</ObjectDataProvider.ConstructorParameters>
</ObjectDataProvider>
<ObjectDataProvider x:Key="AllPatientsDS" ObjectType="{x:Type local:clsPatients}" />
What's a "best practice" way of testing the database connection and letting the user know that the connection is either bad or the network is down, etc, so that the app doesn't just bomb. Right now, I get the Splash Screen and then a "Program has stopped working" while "Windows is checking for a solution to the problem".
Maybe I'm not thinking but how can I trap this when the only call in my codebehind is to InitializeComponent? Ideally, I would want to trap a database connection error and then redirect to another form that tells the user that the db is not up:
public MainWindow()
{
// Somehow check the DB connection
//before the main form with the
//ObjectDataProvider tries to startup
this.InitializeComponent();
}