/// <summary>
        /// Catches the ConnectionOnStateChange event in order to detect when the connection is open in order to execute the federation statement.
        /// </summary>
        protected virtual void ConnectionOnStateChange(object sender, StateChangeEventArgs stateChangeEventArgs)
        {
            if (stateChangeEventArgs.CurrentState != ConnectionState.Open)
                return;

            ExecuteStatement();
        }
 private void SetState(ConnectionState state)
 {
     var originalState = this.state;
     this.state = state;
     var e = new StateChangeEventArgs(originalState, state);
     OnStateChange(e);
 }
示例#3
0
            void OnConnectionStateChange(object sender, System.Data.StateChangeEventArgs e)
            {
                if (_isOpeningOrClosing)
                {
                    return;
                }

                if (!_isOpeningOrClosing &&
                    e.CurrentState != e.OriginalState &&
                    (e.CurrentState == ConnectionState.Open || e.CurrentState == ConnectionState.Closed))
                {
                    if (e.CurrentState == ConnectionState.Open)
                    {
                        // There is nothing more to do here since an actual connection cannot be opened twice,
                        // it means that is was closed.
                        _directOpen = true;
                    }
                    else
                    {
                        if (!_directOpen)
                        {
                            throw new InvalidOperationException("Direct SqlConnection.Close() is allowed only if it was Open() or OpenAsync() directly.");
                        }
                        _directOpen = false;
                    }
                }
            }
示例#4
0
        protected void Connection_StateChange(Object sender, System.Data.StateChangeEventArgs e)
        {
            if (m_Closing)
            {
                return;
            }

            if (e.OriginalState == System.Data.ConnectionState.Open &&
                (e.CurrentState == System.Data.ConnectionState.Closed ||
                 e.CurrentState == System.Data.ConnectionState.Broken ||
                 e.CurrentState == System.Data.ConnectionState.Connecting))
            {
                //Estaba OK y ahora está mal
                while (true)
                {
                    var intentos = 10;
                    while (this.DbConnection.State != System.Data.ConnectionState.Open && intentos-- > 0)
                    {
                        try {
                            this.Open();
                        } catch {
                            System.Threading.Thread.Sleep(1000);
                        }
                    }
                    if (this.DbConnection.State == System.Data.ConnectionState.Open)
                    {
                        break;
                    }
                    else if (--intentos == 0)
                    {
                        break;
                    }
                }
            }
        }
示例#5
0
 void con_StateChange(object sender, System.Data.StateChangeEventArgs e)
 {
     if (e.CurrentState == System.Data.ConnectionState.Closed)
     {
         Dispose();
     }
 }
示例#6
0
 void Con_StateChange(object sender, StateChangeEventArgs e)
 {
     string Mes;
     Mes = string.Format("원래 상태 : {0}, 현재 상태 {1}",
         e.OriginalState, e.CurrentState);
     listBox1.Items.Add(Mes);
 }
示例#7
0
 private void connection_StateChange(object sender, System.Data.StateChangeEventArgs e)
 {
     connectToDbToolStripMenuItem1.Enabled =
         (e.CurrentState == ConnectionState.Closed);
     disconnectDbToolStripMenuItem1.Enabled =
         (e.CurrentState == ConnectionState.Open);
 }
示例#8
0
 void Connection_StateChange(object sender, System.Data.StateChangeEventArgs e)
 {
     if (e.CurrentState == ConnectionState.Open && Connection is SqlConnection && !string.IsNullOrWhiteSpace(Globals.Settings.MtSearchDbCommandAfterOpenConnection))
     {
         var commandArithabortOn = new SqlCommand(Globals.Settings.MtSearchDbCommandAfterOpenConnection, Connection as SqlConnection);
         commandArithabortOn.ExecuteNonQuery();
     }
 }
 protected virtual void OnStateChange(StateChangeEventArgs stateChange)
 {
     StateChangeEventHandler handler = this._stateChangeEventHandler;
     if (handler != null)
     {
         handler(this, stateChange);
     }
 }
 private void sqlConnection1_StateChange(
     object sender, System.Data.StateChangeEventArgs e)
 {
     Console.WriteLine(
         "State has changed from " +
         e.OriginalState + " to " +
         e.CurrentState
         );
 }
示例#11
0
		public static void Connection_StateChange(object sender, System.Data.StateChangeEventArgs e) {
			bool isClosed = e.CurrentState == ConnectionState.Closed;
			if (isClosed ^ wasClosed)
			{
				if (ConnectionStateChanged != null)
					ConnectionStateChanged(!isClosed);
			}
			wasClosed = isClosed;
		}
示例#12
0
        private static void OnStateChange(object sender, StateChangeEventArgs args)
        {
            // If the connection is closed, wake-up the main thread
            PolyConnection connection = (PolyConnection)sender;

            if (connection.State == ConnectionState.Closed)
            {
                WaitHandle.Set();
            }
        }
		private void DBContextChange(object sender, StateChangeEventArgs e) {
			if (e.OriginalState == ConnectionState.Closed && e.CurrentState == ConnectionState.Open) {
				Debug.WriteLine(iDBCounter + " ================ " + DateTime.UtcNow.ToString() + " ================");
				Debug.WriteLine(iDBCounter + " ~~~~~~~~~~~~~~~~ OPEN ~~~~~~~~~~~~~~~~~~");
				ThisWatch.Reset();
				ThisWatch.Start();
			} else if (e.OriginalState == ConnectionState.Open && e.CurrentState == ConnectionState.Closed) {
				ThisWatch.Stop();
				Debug.WriteLine(String.Format("\t SQL took {0}ms   \r\n", ThisWatch.ElapsedMilliseconds));
				Debug.WriteLine(iDBCounter + " ~~~~~~~~~~~~~~~~ CLOSE ~~~~~~~~~~~~~~~~~~");
			}
		}
示例#14
0
        private void _conn_StateChange(object sender, System.Data.StateChangeEventArgs e)
        {
            if (Globals.FDAStatus != Globals.AppState.Normal)
            {
                return;
            }

            if ((e.CurrentState == System.Data.ConnectionState.Broken || e.CurrentState == System.Data.ConnectionState.Closed) && e.OriginalState == System.Data.ConnectionState.Open)
            {
                Error?.Invoke(this, new Exception("Database connection lost"));
            }
        }
示例#15
0
 private static void Connection_StateChange(object sender, StateChangeEventArgs e)
 {
     if ((e.OriginalState == ConnectionState.Broken || e.OriginalState == ConnectionState.Closed || e.OriginalState == ConnectionState.Connecting) &&
         e.CurrentState == ConnectionState.Open)
     {
         DbConnection connection = (DbConnection)sender;
         using (DbCommand command = connection.CreateCommand())
         {
             // Activated foreign keys if supported by SQLite.  Unknown pragmas are ignored.
             command.CommandText = "PRAGMA foreign_keys = ON";
             command.ExecuteNonQuery();
         }
     }
 }
 private void Connection_StateChange(object sender, System.Data.StateChangeEventArgs e)
 {
     if (e.CurrentState == ConnectionState.Open)
     {
         var cmd = connection.CreateCommand();
         cmd.CommandText = @"exec sp_set_session_context @key=N'TenantId', @value=@TenantId";
         cmd.Parameters.AddWithValue("@TenantId", tenantId);
         cmd.ExecuteNonQuery();
     }
     else if (e.CurrentState == ConnectionState.Closed)
     {
         connection.StateChange -= Connection_StateChange;
     }
 }
示例#17
0
        static void connection_StateChange(object sender, System.Data.StateChangeEventArgs e)
        {
            SqlConnection connection = sender as SqlConnection;



            MessageBox.Show                 //вывод информации о соединении и его состоянии
            (
                "Connection to" + Environment.NewLine +
                "Data Source: " + connection.DataSource + Environment.NewLine +
                "Database: " + connection.Database + Environment.NewLine +
                "State: " + connection.State
            );
        }
 private void OnStateChange(object sender, StateChangeEventArgs args)
 {
     if (args.OriginalState == ConnectionState.Closed && args.CurrentState == ConnectionState.Open)
     {
         countCloseOpen++;
     }
     else if (args.OriginalState == ConnectionState.Open && args.CurrentState == ConnectionState.Closed)
     {
         countOpenClose++;
     }
     else
     {
         countOtherConnectionStates++;
     }
 }
 public static void OnStateChange(Object o, StateChangeEventArgs stateChanged)
 {
     // linq seems to switch between open and close only
     if (stateChanged.OriginalState == ConnectionState.Open && stateChanged.CurrentState == ConnectionState.Closed)
     {
         // write the time between open => close
         var timeSpan = DateTime.Now.Subtract(tsStart);
         if (timeSpan.TotalSeconds > 0)
             LogItemHandler.ConnectionClosed(timeSpan);
     }
     else if (stateChanged.OriginalState == ConnectionState.Closed && stateChanged.CurrentState == ConnectionState.Open)
     {
         tsStart = DateTime.Now;
     }
 }
示例#20
0
        void Connection_StateChange(object sender, System.Data.StateChangeEventArgs e)
        {
            if (e.CurrentState != ConnectionState.Open)
            {
                return;
            }

            var connection = (Oracle.ManagedDataAccess.Client.OracleConnection)sender;

            Oracle.ManagedDataAccess.Client.OracleGlobalization info = connection.GetSessionInfo();

            info.Sort       = "TURKISH_AI";
            info.Comparison = "LINGUISTIC";

            connection.SetSessionInfo(info);
        }
 /// <summary>
 /// Constructs the object.
 /// </summary>
 /// <param name="eventType">The type of event being raised.</param>
 /// <param name="eventArgs">The base <see cref="EventArgs" /> associated
 /// with this event, if any.</param>
 /// <param name="transaction">The transaction associated with this event, if any.</param>
 /// <param name="command">The command associated with this event, if any.</param>
 /// <param name="text">The command or message text, if any.</param>
 /// <param name="data">The extra data, if any.</param>
 internal ConnectionEventArgs(
     SQLiteConnectionEventType eventType,
     StateChangeEventArgs eventArgs,
     IDbTransaction transaction,
     IDbCommand command,
     string text,
     object data
     )
 {
     EventType = eventType;
     EventArgs = eventArgs;
     Transaction = transaction;
     Command = command;
     Text = text;
     Data = data;
 }
示例#22
0
        private void Connection_StateChange(object sender, System.Data.StateChangeEventArgs e)
        {
            //if (CanUseSessionContext && e.CurrentState == ConnectionState.Open && _HttpContextAccessor.HttpContext.User.Identity.IsAuthenticated)
            //{
            //    //Get the username from his claims
            //    Guid userId = Guid.Parse(_HttpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value);

            //    var connection = sender as SqlConnection;

            //    var cmd = connection.CreateCommand();
            //    cmd.CommandText = @"exec sp_set_session_context @key=N'UserId', @value=@UserId";
            //    cmd.Parameters.AddWithValue("@UserId", userId);

            //    try
            //    {
            //        cmd.ExecuteNonQuery();
            //    }
            //    catch //This is because the dev server is working with Sql Server 2014 and we need SQL Server 2016
            //    {
            //        CanUseSessionContext = false;
            //    }
            //}
        }
示例#23
0
        private void _DBConnection_StateChange(object sender, System.Data.StateChangeEventArgs e)
        {
            if (!this._eventFiredByOwnConnectionKill)
            {
                if (e.OriginalState == ConnectionState.Open)
                {
                    if (e.CurrentState == ConnectionState.Broken | e.CurrentState == ConnectionState.Closed)
                    {
                        try
                        {
                            if (DBConnectionLostEvent != null)
                            {
                                DBConnectionLostEvent(e.OriginalState, e.CurrentState);
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }

            this._eventFiredByOwnConnectionKill = false;
        }
示例#24
0
		internal void CreateStateChange (ConnectionState original, ConnectionState current)
		{
			StateChangeEventArgs a = new StateChangeEventArgs (original, current);
			OnStateChange (a);
		}
示例#25
0
 private void m_connection_StateChange(object sender, StateChangeEventArgs e)
 {
     if (e.CurrentState == ConnectionState.Closed && Enabled)
     {
         // Connection lost,
         // attempt to reconnect
         Start();
     }
 }
示例#26
0
 private static void _conn_StateChange(object sender, System.Data.StateChangeEventArgs e)
 {
     //throw new NotImplementedException();
 }
示例#27
0
 void connection_StateChange(object sender, StateChangeEventArgs e)
 {
     if (e.CurrentState == ConnectionState.Closed)
     {
         connection.StateChange -= connection_StateChange;
         connection = null;
     }
 }
示例#28
0
 void c_StateChange(object sender, StateChangeEventArgs e)
 {
     stateChangeCount++;
 }
示例#29
0
 static void sqlConnection_StateChange(object sender, System.Data.StateChangeEventArgs e)
 {
     //mainForm.tlblDatabaseStatus.Text = "Database: " + getConnectionStatus(e.CurrentState);
 }
示例#30
0
    /// <summary>
    /// Raises the state change event when the state of the connection changes
    /// </summary>
    /// <param name="newState">The new state.  If it is different from the previous state, an event is raised.</param>
    internal void OnStateChange(ConnectionState newState)
    {
      // FIXME: breaks when the commented out code is used
      ConnectionState oldState = _connectionState;
      _connectionState = newState;

//      if (StateChange != null && oldState != newState)
      if (oldState != newState)
      {
        StateChangeEventArgs e = new StateChangeEventArgs(oldState, newState);
        //StateChange(this, e);
	base.OnStateChange (e);
      }
    }
示例#31
0
 void connection_StateChange(object sender, System.Data.StateChangeEventArgs e)
 {
     writeOutputText(String.Format("Database connection state change: {1} -> {0}.", e.CurrentState, e.OriginalState));
 }
 public static void LogConnectionEvent(this ILogger @this, System.Data.StateChangeEventArgs e)
 {
     @this.Log("Connection state changed From " + e.OriginalState.ToString() + " to " + e.CurrentState.ToString(), LogCategory.Connection, LogLevel.Info);
 }
示例#33
0
		protected virtual void OnStateChange (StateChangeEventArgs stateChange)
		{
			if (StateChange != null)
				StateChange (this, stateChange);
		}
示例#34
0
 public void LogConnectionEvent(System.Data.StateChangeEventArgs e)
 {
     Debug.WriteLine("Connection state changed From " + e.OriginalState.ToString() + " to " + e.CurrentState.ToString(), DS_EVENT);
 }
示例#35
0
        //---------------------------------------------------------------------------

        private static void conn_StateChange(object sender, System.Data.StateChangeEventArgs e)
        {
            Console.WriteLine("StateChange event occurred (sender: " + sender.ToString() + ")");
            Console.WriteLine("\tFrom (OriginalState): " + e.OriginalState.ToString() + "\n\tTo (CurrentState): " + e.CurrentState.ToString());
        }
示例#36
0
 private void connection_StateChange(object sender, System.Data.StateChangeEventArgs e)
 {
     Connect.Enabled    = (e.CurrentState == ConnectionState.Closed);
     Disconnect.Enabled = (e.CurrentState == ConnectionState.Open);
 }
    /// <summary>
    /// Raises the state change event when the state of the connection changes
    /// </summary>
    /// <param name="newState">The new connection state.  If this is different
    /// from the previous state, the <see cref="StateChange" /> event is
    /// raised.</param>
    /// <param name="eventArgs">The event data created for the raised event, if
    /// it was actually raised.</param>
    internal void OnStateChange(
        ConnectionState newState,
        ref StateChangeEventArgs eventArgs
        )
    {
        ConnectionState oldState = _connectionState;

        _connectionState = newState;

        if ((StateChange != null) && (newState != oldState))
        {
            StateChangeEventArgs localEventArgs =
                new StateChangeEventArgs(oldState, newState);

            StateChange(this, localEventArgs);

            eventArgs = localEventArgs;
        }
    }
示例#38
0
		private void connection_StateChange(object sender, StateChangeEventArgs e)
		{
			var state = e.CurrentState == ConnectionState.Open ? ConnectionStates.Open : ConnectionStates.Closed;
			RaiseConnectionStateChanged(state);
		}
示例#39
0
文件: Form1.cs 项目: Mitzury/ITMO
        private void connection_StateChange(object sender, System.Data.StateChangeEventArgs e)

        {
        }
		private void OnStateChange(StateChangeEventArgs args)
		{
			if(StateChange != null)
				StateChange(this, args);
		}
示例#41
0
 void _DBCaller_StateChanged(object sender, System.Data.StateChangeEventArgs e)
 {
     bool x = this.DBConnected;
 }
示例#42
0
文件: MainForm.cs 项目: wyntung/MES
        public void mainConnection_StateChange(object sender, StateChangeEventArgs e)
        {
            //显示数据库当前状态
            string strCurrentStatus;
            if (e.CurrentState.ToString().Equals("Open"))
                strCurrentStatus = "已连接";
            else if (e.CurrentState.ToString().Equals("Closed"))
                strCurrentStatus = "已关闭";
            else if (e.CurrentState.ToString().Equals("Connecting"))
                strCurrentStatus = "正在连接";
            else if (e.CurrentState.ToString().Equals("Executing"))
                strCurrentStatus = "正在执行";
            else if (e.CurrentState.ToString().Equals("Fetching"))
                strCurrentStatus = "正在检索";
            else if (e.CurrentState.ToString().Equals("Broken"))
                strCurrentStatus = "连接中断";
            else
                strCurrentStatus = "未知";

            statusBarPanel2.Text = strCurrentStatus;
        }
示例#43
0
 void Connection_StateChange(object sender, System.Data.StateChangeEventArgs e)
 {
     State = e.CurrentState;
 }
示例#44
0
 protected virtual void OnStateChange(StateChangeEventArgs stateChange)
 {
     StateChangeEventHandler handler = _stateChangeEventHandler;
     if (null != handler)
     {
         handler(this, stateChange);
     }
 }
示例#45
0
 private static void Connection_StateChange(object sender, System.Data.StateChangeEventArgs e)
 {
     Console.WriteLine("\nDB connection status: " + e.CurrentState + "\n");
 }
 private void Conn_StateChange(object sender, System.Data.StateChangeEventArgs e)
 {
     _hubContext.Clients.All.SendAsync("Current State: " + e.CurrentState.ToString()
                                       + " Original State: " + e.OriginalState.ToString(), "connection state changed");
 }
示例#47
0
 void Conn_StateChange(object sender, StateChangeEventArgs e) {
   bool isClosed = e.CurrentState == ConnectionState.Closed;
   //Check that it is being closed by proper calls, not by garbage collector cleaning up
   var callStack = Environment.StackTrace;
   bool calledConnClose = callStack.Contains("Vita.Data.DataConnection.Close()");
   bool calledPostProcessResponse = callStack.Contains("Vita.Web.WebCallContextHandler.PostProcessResponse(");
   _connectionCloseReport = string.Format("{0},{1},{2}", isClosed, calledConnClose, calledPostProcessResponse);
 }
 public static void OnStateChange(object sender, System.Data.StateChangeEventArgs e)
 {
     Console.WriteLine("Connection State Chnaged: {0}", ((SqlConnection)sender).State);
 }
示例#49
0
 void myconn_StateChange(object sender, StateChangeEventArgs e)
 {
     if (myconn.State == ConnectionState.Open)
     {
         //
     }
     if (myconn.State == ConnectionState.Closed)
     {
         //
     }
     if (myconn.State == ConnectionState.Connecting)
     {
         //
     }
     Application.DoEvents();
 }
示例#50
0
 public void OnStateChange(object sender, StateChangeEventArgs e)
 {
     Console.WriteLine("OnStateChange");
     Console.WriteLine("  event args: (" +
            "originalState=" + e.OriginalState +
            " currentState=" + e.CurrentState + ")");
 }
 private void OnClose ()
 {
     if (StateChange != null)
     {
         StateChangeEventArgs args = new StateChangeEventArgs (ConnectionState.Open, ConnectionState.Closed);
         StateChange (this, args);
     }
 }
示例#52
0
		private void OnStateChange (StateChangeEventArgs e) 
		{
			if (StateChange != null)
				StateChange (this, e);
		}
示例#53
0
 private void Connection_StateChange(object sender, System.Data.StateChangeEventArgs e)
 {
     WriteLog($"Connection State: {e.CurrentState}");
 }
示例#54
0
    /// <summary>
    /// Raises the state change event when the state of the connection changes
    /// </summary>
    /// <param name="newState">The new state.  If it is different from the previous state, an event is raised.</param>
    internal void OnStateChange(ConnectionState newState)
    {
      ConnectionState oldState = _connectionState;
      _connectionState = newState;

      if (StateChange != null && oldState != newState)
      {
        StateChangeEventArgs e = new StateChangeEventArgs(oldState, newState);
        StateChange(this, e);
      }
    }
示例#55
0
 static void CStateChange(object sender, StateChangeEventArgs e)
 {
     Console.WriteLine("o status da conexão foi de {0} para {1}", e.OriginalState, e.CurrentState);
 }
 void StateChangeHandler(object sender, StateChangeEventArgs e)
 {
     OnStateChange(e);
 }
示例#57
0
		private void StateChangeHandler(object sender, StateChangeEventArgs e)
		{
		}