我的C#應用程序中使用DataSet
和TableAdapters
。它們是從VS2008 GUI工具生成的。什麼是處理在Windows窗體應用程序連接字符串的最佳方法是什麼?
例子:
右鍵項目 - >添加新項 - >數據集
此方法會自動添加一個連接字符串到app.config
。
但是,這是連接字符串硬繩方法。我想以簡單的方式更改連接字符串。但是,當我使用數據集,然後連接字符串從應用程序屬性中獲取。 這種情況是否有解決方案?
這是我的連接字符串店Settings.Designer.cs文件
namespace WindowsFormsApplication2.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 {
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=SLCERT\\SQLEMK;Initial Catalog=TestDataBase;Integrated Security=True")]
public string TestDataBaseConnectionString {
get {
return ((string)(this["TestDataBaseConnectionString"])); // this is the connection string get from the dataset's
}
}
}
}
的app.config包含
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="WindowsFormsApplication2.Properties.Settings.TestDataBaseConnectionString"
connectionString="Data Source=SLCERT\SQLEMK;Initial Catalog=TestDataBase;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
什麼應用程序做的不是簡單的方法? – alerya 2013-03-25 08:22:28
什麼比編輯app.config更簡單? – 2013-03-25 08:24:30
應用程序。配置伴隨您的應用程序。它的XML。可以在任何文本編輯器中輕鬆編輯 – 2013-03-25 08:25:04