i want to change a connection string to read from web.Config instead of hard coded connection string. this is the connection string that i want to change
Loading
i want to change a connection string to read from web.Config instead of hard coded connection string. this is the connection string that i want to change
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ramesh PalanivelRank #372 · 6.8K reputationPosted Jul 5, 2023, 2:48 AM EDT
HI Yolula,
Are you getting any error ?
yolula SISILANA8 reputationPosted Jul 5, 2023, 2:54 AM EDT
no. how do i change it
Deepak RawatRank #646 · 3.7K reputationPosted Jul 5, 2023, 3:01 AM EDT
Open the web.config file of your project.
Locate the
section within theelement.Replace the existing connection string entry with the following code:
Save the web.config file.
In your code, you can now retrieve the connection string using the
ConfigurationManager.ConnectionStringsproperty. Here's an example of how you can modify your code:using System.Configuration; // ... string connectionString = ConfigurationManager.ConnectionStrings["HeadOfficeEntitiesV2"].ConnectionString;yolula SISILANA8 reputationPosted Jul 5, 2023, 3:37 AM EDT
in the web.config file the connection string already exists. i want to link it so that it reads from web.config instead of hard coded connection string
Prasad RaveendranRank #320 · 7.8K reputationPosted Jul 6, 2023, 9:29 PM EDT
I'm wondering whether you have web.config transformation. if yes, you can update your connection string there. Based on the environment, you can update the connection string in each web.config transformation