I’m dealing with a C# application with a EntityFramework backbone using a DbContext.
The application has two choices: connect to a remote SQL server express or connect to a local SQL compact 4.0 database in case the network connection is not available.
When my application starts, a thread is checking if a connection to the remote database is possible. Otherwise it automatically needs to switch the connection string and provider in order to connect to the local database.
So far I was trying to deal with this issue by modifying the connection string section in app.config and forcing the application to refresh the section, after saving the configuration. This approach is not the best since I need to have access rights to write into the app.config file.
Could you suggest a better approach?
I’m dealing with a C# application with a EntityFramework backbone using a DbContext. The
Share
The DbContext constructor accepts either the name of the connection string, or the actual connection string you want to choose.
What you could do, is test your initial connection string – maybe with a quick ado connection or something simple, and then if it connects use it, otherwise connect using your other one.
Some pseudocode: