<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head>
<title>SqlConnection Example</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server">
string html;
protected void Page_Load ( Object src, EventArgs e ) {
string strConn = ConfigurationManager.ConnectionStrings [ "aspnet" ].ToString ( );
// connect to data source
SqlConnection myConn = new SqlConnection ( strConn );
// open the data connection
myConn.Open ( );
// retrieve properties of the connection object
html += "<table cellspacing=1 class=data width=90%>";
html += "<tr><td><b>ConnectionString</b></td>";
html += "<td>data source=xxx; initial catalog=xxx; user id=xxx;</td></tr>";
html += "<tr><td><b>ConnectionTimeout</b></td>";
html += "<td>" + myConn.ConnectionTimeout + "</td></tr>";
html += "<tr><td><b>Database</b></td>";
html += "<td>" + myConn.Database + "</td></tr>";
html += "<tr><td><b>DataSource</b></td>";
html += "<td>xxx</td></tr>";
html += "<tr><td><b>PacketSize</b></td>";
html += "<td>" + myConn.PacketSize + "</td></tr>";
html += "<tr><td><b>ServerVersion</b></td>";
html += "<td>" + myConn.ServerVersion + "</td></tr>";
html += "<tr><td><b>State</b></td>";
html += "<td>" + myConn.State + "</td></tr>";
html += "<tr><td><b>WorkstationId</b></td>";
html += "<td>" + myConn.WorkstationId + "</td></tr>";
html += "</table>";
// close the data connection
myConn.Close ( );
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>ADO.NET Primer: <b>
SqlConnection</b> Example</h2></div>
<hr size=1 width=92%>
<center>
<p><i>Properties of current <b>
SqlConnection</b> object</i></p>
<%= html %>
</center>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>