本来是在一个Settings.settings 的 Settings.Designer.cs中想更改一个连接字符串为动态的
代码如下:
//------------------------------------------------------------------------------// <auto-generated>// This code was generated by a tool.// Runtime Version:2.0.50727.4927//// Changes to this file may cause incorrect behavior and will be lost if// the code is regenerated.// </auto-generated>//------------------------------------------------------------------------------using Microsoft.Win32;namespace Common.Properties{ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { string DataString = ""; //public void Settings() //{ // if (GetRegistData("ServerIP") != "") // { // DataString = GetRegistData("ServerIP"); // } //} private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); public static Settings Default { get { return defaultInstance; } } [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)] [global::System.Configuration.DefaultSettingValueAttribute("Data Source=" + DataString + ";Initial Catalog=DB;Persist Security Info=True;Us" + "er ID=sa;Password=sa")] public string HighwayDBConnectionString { get { return ((string)(this["DBConnectionString"])); } } //读取指定键路径的值 public static string GetRegistData(string name) { string registData = ""; try { RegistryKey hkml = Registry.LocalMachine; RegistryKey regServerIP = hkml.OpenSubKey("SOFTWARE/YYDZ/Highway", true); registData = regServerIP.GetValue(name).ToString(); } catch { } return registData; } }}
我要怎么做啊,现在这样的话注释掉的代码:
//public void Settings() //{ // if (GetRegistData("ServerIP") != "") // { // DataString = GetRegistData("ServerIP"); // } //}