How to configure a connection to the C # application database easily for development and production without changing code and recompilation?

advertisements

I'm creating a simple C# Windows Forms application that connects to a SQL Server database. We have a different server for developing and production, and now I'm changing the IP address of the server directly inside the code.

The application is going to be deployed, and I am looking for a way to configure things like database server, database name, etc, without changing the code and recompiling. This change will make easier to debug and deploy the application.

What is the recommended way to separate the configuration from the code?


Add an app.config file to your application and store your database connection settings in there.

This will allow you to simply modify the config file without having to recompile the whole application.