<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="Default"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Connection String Builders</title>
</head>
<body>
<div id="pageContent">
<form id="form1" runat="server">
<table>
<tr>
<td><b>User ID</b></td>
<td><asp:TextBox ID="UID" runat="server" width="200px"
text="Dino"></asp:TextBox></td>
</tr>
<tr>
<td><b>Password</b></td>
<td><asp:TextBox ID="Pwd" runat="server" TextMode="Password" width="200px" /></td>
</tr>
<tr>
<td><b>Server</b></td>
<td><asp:TextBox ID="SourceName" runat="server" text="(local)" width="200px" /></td>
</tr>
</table>
<asp:Button runat="server" ID="CreateButton" Text="Create" OnClick="CreateButton_Click" />
<hr />
<asp:Label ID="NewConnString" runat="server" />
</form>
</div>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default : System.Web.UI.Page {
protected void CreateButton_Click(object sender, EventArgs e) {
string serverName = SourceName.Text;
string userid = UID.Text;
string pswd = Pwd.Text;
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = serverName;
builder.UserID = userid;
builder.Password = pswd;
NewConnString.Text = builder.ConnectionString;
}
}
|