this is simple example to open and close connection in .net just use it with out hesitation and do not forget to include required name space like

using System;

using System.Data.SqlClient;
using System.Data;

 

namespace Common
{
    public class Common
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["connection"]);
       

        public SqlConnection opendb()
        {
            try
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                else
                {
                    con.Close();
                    con.Dispose();
                    con.Open();
                }
                return con;
            }
            catch
            {
            }
        }

        public SqlConnection closedb()
        {
            try
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
                return con;
            }
            catch
            {
            }
        }
    }
}


Like it on Facebook, Tweet it or share this article on other bookmarking websites.

Comments (0)

There are no comments posted here yet

What should India do in Maldives?

After all, it is in our immediate neighbourhood

No answer selected. Please try again.
Please select either existing option or enter your own, however not both.
Please select minimum 0 answer(s) and maximum 3 answer(s).
/polls/politics/6234-what-should-india-do-in-maldives.json?task=poll.vote
6234
radio
[{"id":"21494","title":"Intervene opnenly","votes":"42","type":"x","order":"0","pct":54.55,"resources":[]},{"id":"21495","title":"Intervene covertly","votes":"16","type":"x","order":"0","pct":20.78,"resources":[]},{"id":"21496","title":"Watch from sidelines","votes":"19","type":"x","order":"0","pct":24.68,"resources":[]}] ["#ff5b00","#4ac0f2","#b80028","#eef66c","#60bb22","#b96a9a","#62c2cc"] ["rgba(255,91,0,0.7)","rgba(74,192,242,0.7)","rgba(184,0,40,0.7)","rgba(238,246,108,0.7)","rgba(96,187,34,0.7)","rgba(185,106,154,0.7)","rgba(98,194,204,0.7)"] 350
bottom 200
No married couple wants to end up getting divorced. It is not like they have planned for it. They try to put up with their partners for as long as they
Due to our modern lifestyle, we feel that digestion related disorders are a common problem. Thus, we neither give importance to them nor seek any help
The bond of marriage brings the two people together. Initially, everything may seem okay and both of them slowly start discovering each other in the journey.
Your online reputation is important You should know that it takes decades to make your reputation but to ruin it you need just couple of minutes and this
Basics of Cookies is Asp.Net Through this article you are able to know about the following points:1> What are the cookies?2> How to write and read cookies
  Introduction A Web server hosts information in the form of HTML files. The Web server is usually passive and merely acts as an efficient interface
Best language to learn .NET language is the best thing to learn. It has somewhat similar syntax as java and it’s a Microsoft Technology moreover it
If you decide to have an  opt-in list is not just a matter of sending your subscribers your promotional newsletters or catalogs. There are several things