To know connection is opened or not in asp.net.

Jitendrasoft09
Posted by Jitendrasoft09 under C# category on | Points: 40 | Views : 597
using System;
using System.Data;
using System.Data.SqlClient;

class jkexample {

static void Main(string[] args) {


SqlConnection myConnection = new SqlConnection();


myConnection.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Northwind\Northwind.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";


myConnection.Open();


if (myConnection.State == ConnectionState.Open) {
Console.WriteLine("Connection is open");
} else {
Console.WriteLine("Connection is closed");
}


myConnection.Close();


Console.ReadLine();
}
}

Comments or Responses

Login to post response