SqlConnection 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;

 

public class Connection

{

    public Connection()

    {

    }

 

    SqlConnection con;

 

    public SqlConnection openConnection()

    {

        con = new SqlConnection(ConfigurationManager.ConnectionStrings["Baglan"].ConnectionString);

        con.Open();

        return con;

    }

 

    public void closeConnection()

    {

        if (con.State == ConnectionState.Open)

        {

            con.Close();

            con.Dispose();

        }

    }

}

 

 

     /* KULLANIMI;

    

        SqlConnection con;

     

        Connection Baglan = new Connection();

 

        con = Baglan.openConnection();

 

        Baglan.closeConnection();

     

      */