<%@ Page Language="C#" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
void cmdConnect_OnClick(Object sender, EventArgs e)
{
String connectString = ConnectionsList.SelectedItem.Text;
SqlConnection sqlConn = null;
try
{
sqlConn = new SqlConnection(connectString);
sqlConn.Open();
lblConnectInfo.Text = "Connection successful!";
}
catch
{
lblConnectInfo.Text = "Connection failed!";
}
finally
{
if (sqlConn != null)
sqlConn.Close();
}
}
</script>
<html>
<head>
<title>Default</title>
</head>
<body>
<form id="form1" method="post" runat="server">
<b>Note: None of these actually work for this demo.</b><br/>
<asp:DropDownList id="ConnectionsList" runat="server">
<asp:listitem value="logonpassword">User ID=user;Password=pass;Initial Catalog=Northwind;Data Source=(local)</asp:listitem>
<asp:listitem value="IntegratedSecurity">Integrated Security=yes;Initial Catalog=Northwind;Data Source=(local)</asp:listitem>
</asp:DropDownList>
<asp:Button id="cmdConnect" onclick="cmdConnect_OnClick" runat="server" Text="Connect"></asp:Button><br />
<asp:Label id="lblConnectInfo" runat="server"></asp:Label>
</form>
</body>
</html>
|