Using System.Data; Using System.Data.SqlClient;
<%@ Import Namespace="System.Data"%> <%@ Import Namespace="System.Data.SqlClient"%> <%@ Page Language="C#" Debug="true" %> <script runat="server"> SqlConnection objConn; SqlCommand objCmd; void Page_Load(object sender,EventArgs e) { String strConnString; strConnString = "Server= localhost\\SQLEXPRESS; Database= mydatabase; Integrated Security=True;"; objConn = new SqlConnection(strConnString); objConn.Open(); if(objConn.State == ConnectionState.Open) { this.lblText.Text = "SQL Server Connected"; } else { this.lblText.Text = "SQL Server Connect Failed"; } } void Page_UnLoad() { objConn.Close(); objConn = null; } </script> <html> <head> <title>ThaiCreate.Com ASP.NET - SQL Server</title> </head> <body> <form id="form1" runat="server"> <asp:Label id="lblText" runat="server"></asp:Label> </form> </body> </html>