Types of connections in ASP.NET and ADO.NET

1. In App Setting at Webconfig File:

        <appSetting >
            <add key="con" value="Server=admin;database=hms;userid=dileep;pwd=123"/>
        </asssetting>

2. In Connection setting at Webconfig File:

     <connectionStrings>
<add name="con2" connectionString="Initial Catalog=ds;data source=A-61810D2C88704\SQLEXPRESS;integrated                         security=true"/>
<add name="con1" connectionString="Initial Catalog=ds;data source=vishal-hp;integrated security=true;"/>
</connectionStrings>

3. Common Connection(Common Class):

using System;
using System.Data;
using System.Configuration;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DataClass
/// </summary>
public class DataClass
{
    public string strcon;
    public SqlConnection cn;
    public SqlCommand cmd;
   
public DataClass()
{
//
// TODO: Add constructor logic here
         //strcon = "Data Source=RICHA\\SQLEXPRESS;Initial Catalog=NPsilvani;Integrated Security=true;";
        //strcon= "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\NPsilvani.mdf;Integrated Security=True";
        //strcon = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NPsilvani.mdf;Integrated Security=true;User                Instance=True";
        //strcon = @"Data Source=111.118.178.5;DataBase=npsilwan_;Integrated Security=true";
        strcon = ConfigurationManager.ConnectionStrings["rupadbConnectionString"].ConnectionString.ToString();
//a
}

    public  void Openconnection()
    {
        cn = new SqlConnection( strcon);
        cn.Open();
    }

    public  void Closeconnection()
    {

        if (cn.State == ConnectionState.Open)
            cn.Close();
    }

    public  void ExecuteCMD(string str)
    {
        Openconnection();
        cmd = new SqlCommand(str, cn);
        cmd.ExecuteNonQuery();
        Closeconnection();
    }
}

4. In Code Behind Page Directly:

    public string strcon;
    public SqlConnection cn;
    public SqlCommand cmd;
   //strcon = "Data Source=RICHA\\SQLEXPRESS;Initial Catalog=NPsilvani;Integrated Security=true;";
    cn.Open();
    and  last
    cn.close();