ASP.NET MVC Web.config move ConnectionStrings to separate file

Let’s get the connectionStrings inside the web.config file to a separate file for better maintenance of the code.

Step 1: Open your web.config file.

Step 2: You will see your connectionStrings code in there

connectionstring

Step 3: Add a new config file name as ConnectionStrings.config and copy the above code into it

separatefile

Step 4: In your web.config where the code was change the path to the new ConnectionStrings.config file

configchange

Step 5: Run the application normally

Why we did this?

  • Separate code helps better maintenance of the code.
  • Easy change of the connection to database when hosting.
  • Maintain separate files for development and deployment environment.

These are just some options you can do more.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s