2006 2:56:14 PM" / /appSettings /configuration

时间:2022-06-22 08:25:41

1.ConfigurationManager供给对客户端应用措施配置文件的访谒。

其有两个属性1.ConnectionStrings 获取当前应用措施默认配置的 ConnectionStringsSection 数据。

要领一:

string myConn =System.Configuration.ConfigurationManager.ConnectionStrings["sqlConnectionString"].ConnectionString;

要领二:

string connString =System.Web.Configuration.WebConfigurationManager.ConnectionStrings["sqlConnectionString"].ToString();


web.config中的配置为:
<configuration>
<connectionStrings>
    <add connectionString="LocalSqlServer: data source=127.0.0.1;Integrated Security=SSPI;Initial Catalog=aspnetdb"
      providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>

2.AppSettings 获取当前应用措施默认配置的 AppSettingsSection 数据。

string myConn = ConfigurationManager.AppSettings["sqlConnectionString"].ToString();

web.config中的配置为:
<configuration>
<appSettings>
    <add key="sqlConnectionString" value="Monday, January 23, 2006 2:56:14 PM" />
</appSettings>
</configuration>