title: Some tricky quick way to validate oracle db connection
body: <p>My WCF service need to check is connection available now and can we work with it. We have many remote dbs. Their connection are weird sometimes and can't be used to query data or smth else.
  So, for example this is regular connection string used:</p>
  
  <pre><code>User Id=user;Password=P@ssw0rd;Data Source=NVDB1;Connection Timeout=30
  </code></pre>
  
  <p>Here is service method, used for getting </p>
  
  <pre><code>    public List&lt;string&gt; GetAliveDBs(string city)
      {
          if (String.IsNullOrEmpty(city))
              return null;                        
  
          List&lt;string&gt; cityDbs = (from l in alldbs where !String.IsNullOrEmpty(l.Value.city) &amp;&amp; l.Value.city.ToUpper() == city.ToUpper() select l.Value.connString).ToList();            
  
          // There is no such city databases
          if (cityDbs.Count == 0)
              return null;
  
          ReaderWriterLockSlim locker = new ReaderWriterLockSlim();
  
          Parallel.ForEach(cityDbs, p =&gt;
          {
              if (!IsConnectionActive(p.connString))
              {
                  locker.EnterWriteLock();
                  try
                  {
                      cityDbs.RemoveAt(cityDbs.IndexOf(p));
                  }
                  finally
                  {
                      locker.ExitWriteLock();
                  }
              }
          });
  
          return cityDbs;
      }
  
      static public bool IsConnectionAlive(string connectionString)
      {
          using (OracleConnection c = new OracleConnection(connectionString))
          {
              try
              {                    
                  c.Open();
                  if ((c.State == ConnectionState.Open) &amp;&amp; (c.Ping()))
                      return true;
                  else
                      return false;
              }
              catch (Exception exc)
              {
                  return false;                 
              }
          }
      }
  </code></pre>
  
  <p>I use devart components to communicate with Oracle DB.
  Hope for your help, guys! Thanks in advance!</p>