private bool TryUpdateTask(uint ncq_id, DateTime oTaskUpdateTime) { bool bResult = false; try { using (System.Data.IDbConnection dbConnection = GetDbConnection()) { dbConnection.Open(); using (System.Data.IDbCommand oUpdateCommand = dbConnection.CreateCommand()) { oUpdateCommand.CommandText = GetUpdateString(ncq_id, oTaskUpdateTime); bResult = (oUpdateCommand.ExecuteNonQuery() > 0); } } } catch { } return(bResult); }
/// <summary> /// Realiza una conexión con la Base de Datos /// </summary> /// <returns></returns> public bool Connect() { try { // Validar si el 'ConnectionString' es válido if (m_sConnectionString == null || m_sConnectionString.Length == 0) { if (m_oLog != null) { m_oLog.TraceError("La cadena de conexión para la Base de Datos no es válida.", m_idConexion); } throw (new DataAccessException("La cadena de conexión para la Base de Datos no es válida.", -50)); } // Desconectarse si esta actualmente conectado Disconnect(); // Obtener el objeto ADO.NET Conection m_oConnection = GetConnection(); m_oConnection.ConnectionString = m_sConnectionString; // Intentar conectar for (int i = 0; i <= m_nRetryConnect; i++) { if (m_oLog != null) { if (i > 0) m_oLog.TraceLog("Intento de conexion nro: " + i.ToString(), m_idConexion); } try { m_oConnection.Open(); if (m_oConnection.State == ConnectionState.Open) { m_bConnected = true; break; } } catch { if (i == m_nRetryConnect) throw; // Reintentos cada 1 segundo Thread.Sleep(1000); } } // Obtiene el objeto COMMAND m_oCommand = m_oConnection.CreateCommand(); m_oCommand.CommandTimeout = (m_nCommandTimeout > 0) ? m_nCommandTimeout : m_oConnection.ConnectionTimeout; return m_bConnected; } catch (DataAccessException ex) { throw ex; } catch (Exception ex) { throw new DataAccessException("Error no esperado al realizar la conexión.", ex); } }
public bool Connect() { // Check for valid connection string if(m_sConnectionString == null || m_sConnectionString.Length == 0) throw( new Exception("Invalid database connection string")); // Disconnect if already connected Disconnect(); // Get ADONET connection object m_oConnection = GetConnection(); m_oConnection.ConnectionString = this.ConnectionString; // Implement connection retries for(int i=0; i <= m_nRetryConnect; i++) { try { m_oConnection.Open(); if(m_oConnection.State == ConnectionState.Open) { m_bConnected = true; break; } } catch { if(i == m_nRetryConnect) throw; // Wait for 1 second and try again Thread.Sleep(1000); } } // Get command object m_oCommand = m_oConnection.CreateCommand(); m_oCommand.CommandTimeout = m_nCommandTimeout; return m_bConnected; }