<% @Import Namespace="System.Data.SqlClient" %>
<HTML>
	<HEAD>
		<title>连接SQL Server数据库示例</title>
		<script language=C# runat=server>
		
			void Page_Load(object sender, System.EventArgs e)
			{
				// 连接字符串
				string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionSqlServer"];

				// 创建SqlConnection对象
				SqlConnection connection = new SqlConnection(ConnectionString);	
		
				try
				{
					// 打开数据库连接
					connection.Open();									
					myLabel.Text = "连接数据库成功";
				}
				catch
				{
					myLabel.Text = "连接数据库失败";
				}
				finally
				{
					// 关闭数据库连接
					connection.Close();									
				}
			}
		
		</script>
	</HEAD>
	<body>
		<form id="Form1" method="post" runat="server">
			<h3>连接SQL Server数据库示例</h3>
			连接信息：<asp:Label id="myLabel" runat="server"></asp:Label>
		</form>
	</body>
</HTML>
