Wednesday, December 06, 2006 4:07 PM royashbrook

simple .net connection page

<%@ Page Language="C#" %>
<%@ Import namespace="System.Data.SqlClient"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

	protected void Page_Load(object sender, EventArgs e)
	{
		if (Page.IsPostBack)
		{
			try
			{
				dg.DataSource = svht();
				dg.DataBind();
				using (SqlConnection cn = new SqlConnection(t.Text))
				{
						cn.Open();
						l.Text = String.Format("Connection.State = {0}", cn.State);
				}
			}
			catch (Exception ex)
			{
				l.Text = String.Format("Error: {0}", ex.Message);
			}
		}
	}
	protected Hashtable svht()
	{
		Hashtable ht = new Hashtable();
		foreach (string s in Request.ServerVariables.AllKeys)
		{
			ht.Add(s, Request.ServerVariablesSleep);
		}
		return ht;
	}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
	<title>Connection Test Page</title>
</head>
<body>
	<form id="f" runat="server">
	Enter a connection string and click submit:<br />
	<asp:TextBox ID="t" runat="server" Width="500px"></asp:TextBox><br />
	<asp:Button ID="b" runat="server" Text="Submit"/><br /><br />
	Result will show here:<br />
	<asp:Label ID="l" runat="server" ForeColor="red"></asp:Label><br /><br />
	Server variables will show here:
	<asp:DataGrid ID="dg" runat="server" AutoGenerateColumns="false">
		<Columns>
		<asp:BoundColumn DataField="Key" HeaderText="Key"></asp:BoundColumn>
		<asp:BoundColumn DataField="Value" HeaderText="Value"></asp:BoundColumn>
		</Columns>
	</asp:DataGrid>
	</form>
</body>
</html>

Comments

No Comments