Advice on design to handle server connection

Scott Thomson 56 Reputation points
2020-11-02T09:32:12.743+00:00

Hello

I am trying to work out how to include in the design of my WPF, C#, EF6, MVVM App code to handle a case if its SQL database is moved to a new server for example. Can one code for this situation so App can trap exception then allow a new server name to be entered and from then on remember the new server. eg dynamically modifiable connectionstring?

I have been reading on DBExecutionStrategy. Not yet clicked though.

I dont need specific code as I will try and google and work out for myself but pointers on where to start and what resources to read. What the concept would look like to give an App resilience when relying on SQL DB

thanks
Scott

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,765 questions
{count} votes

Accepted answer
  1. Duane Arnold 3,221 Reputation points
    2020-11-02T18:15:24.157+00:00

    You can use Powershell to have user enter info and change the runtime config file. The file must be deployed to the same location as the program.exe file so .NET can find it at runtime..

    https://www.tutorialspoint.com/powershell/index.htm

    https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/

    <copied>

    The name of the configuration file is the name of the app with a .config extension. For example, an app called myApp.exe should have a source configuration file called myApp.exe.config.

    <end>

    The exe.config is in the Bin folder for your VS project along with the program.exe that is created every time you build the project in VS.

    I also suggest that you leave some documentation when you leave the company. :)


1 additional answer

Sort by: Most helpful
  1. Karen Payne MVP 35,416 Reputation points
    2020-11-02T18:32:21.057+00:00

    Hello,

    What we do is to push configuration (and other files that don't require the app to be rebuild) files via active directory to a specific group which has an application that needs a new/modified configuration file. So only the configuration file is replaced.

    The following is slightly off-topic

    Also, if you want to assert if the server is available check out the following class on GitHub where the methods can be called before working with your DbContext or perhaps if an exception is thrown. The example is shown in a windows form app but since the code is in a class the code can be used in any project.

    Then there is the thought of having multiple connections that can change at runtime where the following GitHub repository may be of assistance.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.