Create a new .cs file and creat there a class as like..
public class databaseConnection
{
public static string connectionString = "useYourConnectionStringHere";
}
then in your main class use it as..
SqlConnection con;
private void connect()
{
String s = databaseConnection.connectionString;
con = new SqlConnection(s);
con.Open();
}
private void disConnect()
{
con.Close();
}
then use it in your method or button event as like as..
try
{
connect();
.
.
.
.
}
catch(Exception e)
{
}