我如何在web.config中动态更改sql server 2005密码 [英] how can i change sql server 2005 password dynamically in web.config

查看:64
本文介绍了我如何在web.config中动态更改sql server 2005密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在web.confi中动态更改sql服务器密码?

is it paossible to change sql server password dynamically in web.confi

推荐答案

使用以下功能将更改您的web.config文件

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部分



Web.Config Section

<connectionStrings>
  <add name="EmployeeDB" connectionString="Its a test" />
</connectionStrings>


这篇关于我如何在web.config中动态更改sql server 2005密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆