(一)配置
1.配置示例代码.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<!--数据库配置-->
<add key="DBHost" value ="192.168.0.2" />
<add key="DBName" value="NorthWind" />
<add key="DBUser" value="sa" />
<add key="DBPass" value="" />
<add key="DBMaxConn" value="50" />
<add key="DBMinConn" value="3" />
<add key="DBConnTimeOut" value="3" />
</appSettings>
</configuration>
(二).用法
2.打开命名空间
using System.Configuration;
3.读取示例
string dbhost=ConfigurationSettings.AppSettings["DBHost"].Trim();
string dbname=ConfigurationSettings.AppSettings["DBName"].Trim();
string dbuser=ConfigurationSettings.AppSettings["DBUser"].Trim();
string dbpass=ConfigurationSettings.AppSettings["DBPass"].Trim();
1.配置示例代码.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<!--数据库配置-->
<add key="DBHost" value ="192.168.0.2" />
<add key="DBName" value="NorthWind" />
<add key="DBUser" value="sa" />
<add key="DBPass" value="" />
<add key="DBMaxConn" value="50" />
<add key="DBMinConn" value="3" />
<add key="DBConnTimeOut" value="3" />
</appSettings>
</configuration>
(二).用法
2.打开命名空间
using System.Configuration;
3.读取示例
string dbhost=ConfigurationSettings.AppSettings["DBHost"].Trim();
string dbname=ConfigurationSettings.AppSettings["DBName"].Trim();
string dbuser=ConfigurationSettings.AppSettings["DBUser"].Trim();
string dbpass=ConfigurationSettings.AppSettings["DBPass"].Trim();