Why put connection string in web.config?

I am learning .Net, please help me out regarding this question.

Why do people want to write the connection string in web.config?

Instead we can assign the string to one public variable so that we can access it any where in the application.

What's the advantage of using connection string in web.config?

1 answer

Using web.config you can change the string without compiling and distributing a new application.

Read more here, http://www.connectionstrings.com/store-connection-string-in-webconfig/