Click here to Skip to main content
15,889,442 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
is it paossible to change sql server password dynamically in web.confi
Posted
Comments
Sandeep Mewara 8-Oct-10 4:19am    
Elaborate! What are you trying to do. For now, it doesnt make much sense.

1 solution

Use the following function will change your web.config file

Private Function SaveConnectionStringKey(ByVal configFilePhysicalPath As String, ByVal key As String, ByVal value As String) As Boolean
      Dim m As ExeConfigurationFileMap = New ExeConfigurationFileMap
      m.ExeConfigFilename = configFilePhysicalPath
      Dim objConfig As Configuration = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(m, ConfigurationUserLevel.None)
      Dim objAppsettings As ConnectionStringsSection = objConfig.GetSection("connectionStrings")
      If Not objAppsettings Is Nothing Then
          objAppsettings.ConnectionStrings(key).ConnectionString = value
          objConfig.Save()
      End If
  End Function

To call the function use
SaveConnectionStringKey(Server.MapPath("~/web.config"), "EmployeeDB", "Server=etc;uid=etc.......")


Web.Config Section
XML
<connectionStrings>
  <add name="EmployeeDB" connectionString="Its a test" />
</connectionStrings>
 
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