C#修改connectionStrings的方法
2014-03-22 23:35
246 查看
读取
protected void Page_Load(object sender, EventArgs e) { CheckLogin MyChk = new CheckLogin(); title.InnerHtml = "<b>数据库连接配置</b>"; if (!IsPostBack) { Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath); string myConnect = config.ConnectionStrings.ConnectionStrings["MyApp.Properties.Settings.SqlConnectSetting"].ToString(); string[] arycon = myConnect.Split(';'); int i, li_index; for (i = 0; i < arycon.Length; i++) { if (arycon[i].IndexOf("Data Source") > -1) { li_index = arycon[i].IndexOf("="); TextBox1.Text = arycon[i].Substring(li_index + 1); } if (arycon[i].IndexOf("Initial Catalog") > -1) { li_index = arycon[i].IndexOf("="); TextBox2.Text = arycon[i].Substring(li_index + 1); } if (arycon[i].IndexOf("User ID") > -1) { li_index = arycon[i].IndexOf("="); TextBox3.Text = arycon[i].Substring(li_index + 1); } if (arycon[i].IndexOf("Password") > -1) { li_index = arycon[i].IndexOf("="); TextBox4.Text = arycon[i].Substring(li_index + 1); } } } }
修改
protected void Button1_Click(object sender, EventArgs e) { string ls_newstring = "Data Source=" + TextBox1.Text.Trim() + ";Initial Catalog=" + TextBox2.Text.Trim() + ";Persist Security Info=True;User ID=" + TextBox3.Text.Trim() + ";Password=" + TextBox4.Text.Trim(); Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath); string csName = "MyApp.Properties.Settings.SqlConnectSetting"; ConnectionStringsSection csSection = config.ConnectionStrings; csSection.ConnectionStrings[csName].ConnectionString = ls_newstring; config.Save(ConfigurationSaveMode.Modified); //IIS将重新启动 } }
相关文章推荐
- C#修改文件名方法
- [原创]琢磨一种察看/修改C#堆中东西的方法(随笔)
- c#修改系统时间的方法
- C# WebBrower1控件提示“该文档已被修改,是否保存修改结果”解决方法 .
- c#修改系统时间的方法
- C#实现修改系统时间的方法
- [原创]琢磨一种察看/修改C#堆中东西的方法(随笔)
- C#修改txt文本内容的方法
- (教学思路 C#之类四)构造方法(静态构造方法、this、方法重载)、析构方法(修改新增)
- c#修改系统时间的方法
- C# 添加、修改以及删除Excel迷你图表的方法
- c#修改系统时间的方法
- C#使用非托管代码直接修改字符串的方法
- Visual Studio 2017中使用正则修改部分内容 如何使用ILAsm与ILDasm修改.Net exe(dll)文件 C#学习-图解教程(1):格式化数字字符串 小程序开发之图片转Base64(C#、.Net) jquery遍历table为每一个单元格取值及赋值 。net加密解密相关方法 .net关于坐标之间一些简单操作
- C#创建、读取和修改Excel的方法
- C#中动态修改ListBox的Item的颜色的方法
- C#截取指定长度中英文字符串方法 (修改)
- C#下用zedGraph生成大量数据统计图表的方法(通过修改一些源码)
- (部分已做修改)C#访问远程主机资源的方法---用户模拟角色类
- [C#]对我的网页动态生成图片方法的修改