iis – Asp.Net ADO Firebird System.ArgumentOutOfRangeException: operation=0

I’m having a problem on a system that is running on IIS 10.0.14393.0 with Framework 4.6.1.

System.ArgumentOutOfRangeException: operation=159 Parameter name: operation

The number “159” is random, sometimes it is “0” or even very large “1380273440”

It’s an intermittent problem, but I’ve noticed that the times it occurs are at peak usage times. The error stops when I recycle Connection Pooling within IIS.

  • Firebird 2.1
  • FirebirdSql.Data.FirebirdClient 6.6.0
  • Visual Studio 2022 – Version 17.1.3

I found some links, but I didn’t have the solution for lack of more information. The problem is that the error cannot be reproduced in the development environment.

The error does not occur in the same place and also happens on different forms. I’ve already tried to reproduce the error in the development environment, but I couldn’t.

Below is the code where it occurs most frequently:

protected void Page_Load(object sender, EventArgs e)
{
    if ((Session["NomeUsuario"] == null) || (Session["NomeSistema"].ToString() != Master.Sistema()))
    {
        Response.Redirect("login.aspx");
    }

    tag = Request.QueryString["tag"];

    if (!Page.IsPostBack)
    {
        ControleAcesso controleAcesso = new ControleAcesso();
        string formulario = System.IO.Path.GetFileName(System.Web.HttpContext.Current.Request.Url.AbsolutePath);
        if (controleAcesso.ValidaRotina(Session["NomeSistema"].ToString(), Session["NomeUsuario"].ToString(), formulario.ToLower()) == false) { Response.Redirect("Menu.aspx?acesso=1"); }
        else
        {
            if (controleAcesso.ValidaOpcao(Session["NomeSistema"].ToString(), Session["NomeUsuario"].ToString(), "incluir") == true) { butIncluir.Visible = true; } else { butIncluir.Visible = false; }
            if (controleAcesso.ValidaOpcao(Session["NomeSistema"].ToString(), Session["NomeUsuario"].ToString(), "alterar") == true) { griPadrao.Columns[0].Visible = true; } else { griPadrao.Columns[0].Visible = false; }
            if (controleAcesso.ValidaOpcao(Session["NomeSistema"].ToString(), Session["NomeUsuario"].ToString(), "filhos") == true) { griPadrao.Columns[1].Visible = true; } else { griPadrao.Columns[1].Visible = false; }
            if (controleAcesso.ValidaOpcao(Session["NomeSistema"].ToString(), Session["NomeUsuario"].ToString(), "excluir") == true) { griPadrao.Columns[2].Visible = true; } else { griPadrao.Columns[2].Visible = false; }
            if (controleAcesso.ValidaOpcao(Session["NomeSistema"].ToString(), Session["NomeUsuario"].ToString(), "perfil") == true) { griPadrao.Columns[3].Visible = true; } else { griPadrao.Columns[3].Visible = false; }
            if (controleAcesso.ValidaOpcao(Session["NomeSistema"].ToString(), Session["NomeUsuario"].ToString(), "historico-log") == true) { griPadrao.Columns[4].Visible = true; } else { griPadrao.Columns[4].Visible = false; }
            if (controleAcesso.ValidaOpcao(Session["NomeSistema"].ToString(), Session["NomeUsuario"].ToString(), "listagem") == true) { tabListagem.Enabled = true; } else { tabListagem.Enabled = false; }
        }

        hypRaca.ImageUrl = "~/Imagens/pastafechada.png";
        hypPai.ImageUrl = "~/Imagens/pastafechada.png";
        hypMae.ImageUrl = "~/Imagens/pastafechada.png";
        hypPaiPermanente.ImageUrl = "~/Imagens/dna_nao.png";
        hypMaePermanente.ImageUrl = "~/Imagens/dna_nao.png";
        txtMae.Attributes.Add("onfocus", "this.select()");
        txtPai.Attributes.Add("onfocus", "this.select()");
        tabManutencao.Enabled = false;
        tabPerfilGeral.Enabled = false;
        tabLogHistorico.Enabled = false;
        tabFilhos.Enabled = false;
        tabListagem.Enabled = false;
        txtCadastro.Text = DateTime.Today.ToShortDateString();
        tabCadastro.ActiveTabIndex = 0;
        tabPerfilLinhagemCelular.Enabled = false;
    }
}

public bool ValidaRotina(string sistema, string usuario, string formulario)
{
    using (FbConnection conexao = new FbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Dados"].ToString()))
        try
        {
            FbCommand comando = new FbCommand("select count(1) from SYS_PERMISSAO where SISTEMA=@SISTEMA and USUARIO=@USUARIO and FORMULARIO=@FORMULARIO and ((OPCAO is null) or (OPCAO=''))", conexao);
            comando.Parameters.Add("@SISTEMA", FbDbType.VarChar);
            comando.Parameters.Add("@USUARIO", FbDbType.VarChar);
            comando.Parameters.Add("@FORMULARIO", FbDbType.VarChar);
            comando.Parameters[0].Value = sistema;
            comando.Parameters[1].Value = usuario;
            comando.Parameters[2].Value = formulario.ToLower();
            conexao.Open();
            return !(((int)comando.ExecuteScalar()) > 0);
        }
        catch (Exception erro)
        {
            return false;
        }
        finally
        {
            conexao.Close();
        }
}

public bool ValidaOpcao(string sistema, string usuario, string opcao)
{
    using (FbConnection conexao = new FbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Dados"].ToString()))
        try
        {
            string formulario = System.IO.Path.GetFileName(System.Web.HttpContext.Current.Request.Url.AbsolutePath);

            FbCommand comando = new FbCommand("select count(1) from SYS_PERMISSAO where SISTEMA=@SISTEMA and USUARIO=@USUARIO and FORMULARIO=@FORMULARIO and OPCAO=@OPCAO", conexao);
            comando.Parameters.Add("@SISTEMA", FbDbType.VarChar);
            comando.Parameters.Add("@USUARIO", FbDbType.VarChar);
            comando.Parameters.Add("@FORMULARIO", FbDbType.VarChar);
            comando.Parameters.Add("@OPCAO", FbDbType.VarChar);
            comando.Parameters[0].Value = sistema;
            comando.Parameters[1].Value = usuario;
            comando.Parameters[2].Value = formulario.ToLower();
            comando.Parameters[3].Value = opcao.ToLower();
            conexao.Open();
            return !(((int)comando.ExecuteScalar()) > 0);
        }
        catch (Exception erro)
        {
            return false;                
        }
        finally
        {
            conexao.Close();
        }
}

Leave a Comment