-1

I am using .net, i have doubt about SqlConnection open

  sqlconnection con = new sqlconnection("Constr");

    if (con.State == ConnectionState.Closed) ||( con.State == ConnectionState.Broken)
    { con.open();}

this method now am using this method is best or some programmers using below method

if (con.State == ConnectionState.Open)
{ con.close();}
con.open();

which one is best or which is best

senthilkumar2185
  • 2,536
  • 3
  • 22
  • 36

1 Answers1

2

Why you dont use using?

using (SqlConnection conn = new SqlConnection (...))
{

}

I can this way is better.Also you can use this code:

if (conn != null && conn .State == ConnectionState.Closed)
{

}