Imports System.Data
Imports System.Data.SqlClient

Partial Class _Default
    Inherits System.Web.UI.Page


    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' string variable to store the connection string
        ' defined in appsettings section of web.config file.
        Dim connStr As String = ConfigurationManager.AppSettings("ConnectionString").ToString()

        ' Object created for SQL Connection
        Dim myConnection As New SqlConnection(connStr)

        ' if condition that can be used to check the sql connection
        ' whether it is already open or not.
        If myConnection.State = ConnectionState.Closed Then
            myConnection.Open()
        End If

        ' message string just to display the sql connection state.
        Label1.Text = "ASP.Net 2.0 SQL Database Connection State: <b>" & myConnection.State & "</b>"

        ' if condition that can be used to check the sql connection
        ' if it is open then close it.
        If myConnection.State = ConnectionState.Open Then
            myConnection.Close()
        End If
    End Sub
End Class
