
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<HTML>
	<HEAD>
		<title>使用ConfigurationSettings.AppSettings属性读取自定义配置节示例</title>

		<script language="C#" runat="server">

			void Page_Load(object sender, System.EventArgs e)
			{
				// 从<appSettings>节读取连接字符串
				string ConnString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionSqlServer"];

				// 创建SqlConnection对象
				SqlConnection thisConnection = new SqlConnection(ConnString);

				try
				{
					// 打开连接
					thisConnection.Open();
					Label1.Text = "连接已经打开";
				}
				catch(Exception ex)
				{
					Label1.Text = ex.ToString();
				}
				finally
				{
					// 关闭连接
					thisConnection.Close();
				}
			}

		</script>
		
	</HEAD>
	<body>
		<form id="Form1" method="post" runat="server">
			<h3>使用ConfigurationSettings.AppSettings属性读取自定义配置节示例</h3>
			<asp:Label id="Label1" runat="server">Label</asp:Label>
		</form>
	</body>
</HTML>
