ORA-01000: maximum open cursors exceeded goracle

I have a service that runs a stack. For this, it performs the reading of this stack through a query in Oracle. It turns out that after hours of execution I get the message:

ORA-01000: maximum open cursors exceeded

I wonder what may be going on. I have a global variable that opens the connection and I always check its connection and copy it to the local variable.

In Rows.Next () from what I read, when he checks that there are no more lines he closes the cursor, so I couldn’t have accumulated so many cursors to exceed the limit.

Connection to the bank:

 type GERENCIACON struct {
DataBase *sql.DB
}

func (gc *GERENCIACON) F_FECHAR_CONEXAO() {
gc.DataBase.Close()
}

func (gc *GERENCIACON) F_ABRIR_CONEXAO()  {	
if gc.DataBase == nil || gc.DataBase.Ping() != nil {	
	gc.DataBase, _ = sql.Open("goracle", "X/X@10.0.254.10:1521/orcl")
}
}

var VGGerenciaConexao GERENCIACON

Struct for consultation:

  type GERENCIACONSULTA struct {
DataBase *sql.DB
Rows *sql.Rows
}

func (gc *GERENCIACONSULTA) F_EXECUTA_CONSULTA(pSql string) {
VGGerenciaConexao.F_ABRIR_CONEXAO()
gc.DataBase = VGGerenciaConexao.DataBase
gc.Rows, _ = gc.DataBase.Query(pSql)
}

Service fetching the stack:

   var vGerenciaConsulta CertanoLabsPackage.GERENCIACONSULTA
   var vSQL string

  for {
    	vSQL = "select * from stack "	

       vGerenciaConsulta.F_EXECUTA_CONSULTA(vSQL)

          for vGerenciaConsulta.Rows.Next() {
          ...
         }

    time.Sleep(time.Minute)
 }

What could be happening?

It is possible that an error occurred during the call to vGerenciaConsulta.Rows.Next() causing it to return false and exit the loop. In this case, Close() is not automatically called.

1 Like

Move opening and closing of database connections out of loops.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.