title: Closing a database link in .NET, ORA-02080
body: <p>I have some code that uses a database link that needs to be closed when it's done with.
  I call <code>DBMS_SESSION.Close_database_link</code> but it gives me the error, ORA-02080, even though the link is no longer in use.</p>
  
  <p>When I tried it in SQL*Plus, it worked great and closed after I ran <code>COMMIT</code>.  But in .Net, even if I run commit it doesn't close.</p>
  
  <pre><code>using (var con = new Oracle.DataAccess.Client.OracleConnection(@"Data Source=firefly8;User Id=USER;Password=PWD;Pooling=false;"))
              {
                  con.Open();
                  var c = con.CreateCommand();
                  c.CommandText = "select a from tnoam@link_2";
                  using (var r = c.ExecuteReader())
                  {
                      r.Read();
                  }
                  c.Dispose();
  
                  var c2 = con.CreateCommand();
                  c2.CommandText = "begin commit; dbms_session.close_database_link ('link_2');end;";
  
                  c2.ExecuteNonQuery();
              }
  </code></pre>
  
  <p>I'm pretty stuck with this one. Please Help</p>
  
  <p>Based on the comment from @Ben I tried the following, it didn't work as well:</p>
  
  <pre><code>    using (var con = new Oracle.DataAccess.Client.OracleConnection(@"Data Source=firefly8;User Id=MILK_NEW;Password=MILK_NEW;Pooling=false;"))
  {
      con.Open();
      var t = con.BeginTransaction();
      var c = con.CreateCommand();
      c.Transaction = t;
      c.CommandText = "select a from tnoam@link_2";
      using (var r = c.ExecuteReader())
      {
          r.Read();
      }
      t.Commit();
      c.Dispose();
  
      var c2 = con.CreateCommand();
      c2.CommandText = "begin commit; dbms_session.close_database_link ('link_2');end;";
  
      c2.ExecuteNonQuery();
  }
  </code></pre>