Copy Code code as follows:
Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Web;
Using System.Web.SessionState;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.HTMLControls;
Using System.Data.SqlClient;
Namespace Example01
{
///
Summary description of the WebForm1.
///
public class WebForm1:System.Web.UI.Page
{
private void Page_Load (object sender, System.EventArgs e)
{
Place user code here to initialize page
Response.Write ("First instance of connecting to a database");
SqlConnection myconnection = new SqlConnection ("Server=localhost;uid=sa;pwd=sa");
Try
{
Myconnection.open ()//Open Database link
Response.Write ("link success!") ");
}
Catch
{
Response.Write ("link failed!") ");
}
}
Code generated #region the Web forms Designer
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}
///
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
///
private void InitializeComponent ()
{
This. Load = new System.EventHandler (this. Page_Load);
}
#endregion
}
}