Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am building a Windows Form (WinForm) using Entity Framework 6, I should have 2 different connection strings.

1. a connection string for development mode.
2. a connection string for deployment.

how can I achieve that and easily switch between them?

I need this scenario to check if the Application is still in development mode (DEBUG), use the first connection string and if it is deployed, then use the second one.

What I have tried:

I have already added 2 different connection string in app.config
Posted
Updated 1-Dec-19 5:39am
v2

Well ... there is always this: Debugger.IsAttached Property (System.Diagnostics) | Microsoft Docs[^] which tells your code if a debugger is there.

But ... I'd rather have the app running the same code in release and debug: have a single connection string in your app.config and edit it for the release version(s).
Since you probably don't know what the release connection string will be anyway (it can easily be different for each user as they can have different permissions on the DB, or access different servers) this is probably the safest course.

When you run your app, you check if a config file exists, and create a default one if not - getting the connection string filled in then.
 
Share this answer
 
Comments
Maciej Los 1-Dec-19 7:45am    
5!
In addition to solution #1 by OriginalGriff...

You can define input parameter for running the project in debug mode. See: How to Pass Command Line Arguments using Visual Studio ? - Daily .NET Tips[^]
I'd suggest to use that parameter as a switch between debug/deploy mode.
 
Share this answer
 
I have figured it out myself, using a tool called: SlowCheetah

SlowCheetah - Visual Studio Marketplace[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900