Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8831221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:15:44+00:00 2026-06-14T08:15:44+00:00

I have a WPF desktop application where I want to check if I can

  • 0

I have a WPF desktop application where I want to check if I can connect to my database with EF before launching the main window. So I try to connect to database and if exception occurs, I simply show a window where I ask the user to enter correct database connection string.

After user enters the connection string, I retry connecting to database and if it connects I want to launch my main window and let the application start.

EDIT: I changed my code a liitle bit, but still doesn’t work. I think it is about closing one window and then trying to show another window in Application class. It works if ServerConfigurationWin is not shown.

However what happens is, after I display the database configuration window to user, the application calls the StartupUri window’s constructor declared in App.xaml file but nothing shows on screen.

Thanks.

Here is my App code:

public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);

        bool success = false;
        while (!success)
        {
            try
            {
                DemirbasContext context = new DemirbasContext();
                DbInitializer initializer = new DbInitializer();
                Database.SetInitializer<DemirbasContext>(initializer);
                context.Database.Initialize(false);
                success = true;
            }
            catch (ProviderIncompatibleException)
            {
                ServerConfigurationWin configurationWin = new ServerConfigurationWin();
                if (!configurationWin.ShowThemAll())
                {
                    // ShowThemAll() returns that operation is canceled.
                    App.Current.Shutdown();
                    return;
                }
                success = false;
            }
        }
    }

    public App()
    {

    }

    void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
    {
        // Process unhandled exception do stuff below
        Console.WriteLine("***Message***");
        Console.WriteLine(e.Exception.Message);
        Console.WriteLine("***Stack Trace***");
        Console.WriteLine(e.Exception.StackTrace);
        Console.WriteLine("***Target Site***");
        Console.WriteLine(e.Exception.TargetSite);
        // Prevent default unhandled exception processing
        e.Handled = true;
    }
}

App.xaml:

<Application x:Class="Demirbas.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         DispatcherUnhandledException="App_DispatcherUnhandledException"
         StartupUri="Enterance.xaml">
<Application.Resources>
    <Style TargetType="Button">
        <Setter Property="Height" Value="25" />
        <Setter Property="Width" Value="75" />
        <Setter Property="MinWidth" Value="25" />
        <Setter Property="Margin" Value="5,0" />
        <Setter Property="Padding" Value="0" />
    </Style>
    <Style TargetType="Label">
        <Setter Property="Margin" Value="5,0" />
    </Style>

</Application.Resources>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:15:44+00:00Added an answer on June 14, 2026 at 8:15 am

    It seems you cannot show a second window from your Application class. So I had to shutdown the application and start again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a desktop .NET WPF application witch uses an embedded database (SQLite). Where
I have a WPF desktop application that uses a custom database for storage. I
I have a WPF Desktop application using Prism 4, in my bootstrapper i have
We have created a beautifully designed .NET WPF desktop application. We are installing the
I have created a desktop application in WPF that I wish to supply to
We have a WPF Application that runs from both desktop and as a XBAP
I have WPF Application where I have One main form and other user controls
I have a C# WPF application, I want it, when launched, to change the
In my desktop-based WPF-application I want to implement a toolbar with key actions (add,
I have troubles with WPF desktop application based on Microsoft Prism Framework. The application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.