How to use the StateChange event : SQL Events : Database C# Source Code


Custom Search

C# Source Code » Database » SQL Events »

 

How to use the StateChange event








    

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

class StateChange
{
  public static void StateChangeHandler(object mySender, StateChangeEventArgs myEvent)
  {
    Console.WriteLine("mySqlConnection State has changed from "+myEvent.OriginalState + "to "+myEvent.CurrentState);
  }

  public static void Main(){
    SqlConnection mySqlConnection =new SqlConnection("server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI;");

    mySqlConnection.StateChange +=new StateChangeEventHandler(StateChangeHandler);

    Console.WriteLine("Calling mySqlConnection.Open()");
    mySqlConnection.Open();

    Console.WriteLine("Calling mySqlConnection.Close()");
    mySqlConnection.Close();
  }
}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Database
» SQL Events