locked
System.StackOverFlowException RRS feed

  • Question

  • User1144299848 posted

    Hi Folks,

    I am dealing with a MVC application and I am stuck with a System.StackOverFlowException.

    I have done some research about this error and found that it usually happens with recursive functions calls.

    But I think this is a different  one.

    I got the error when this query runs.

    Select pes.* from pes where pes.pesid in 
    (SELECT pesemp.pesid FROM pesemp 
    Left JOIN emp ON pesemp.empid = emp.empid 
    Left JOIN pesempfco ON pesempfco.pesempid = pesemp.pesempid 
    Left JOIN fco ON pesempfco.fcoid = fco.fcoid 
    Left Join pesemptrb on pesemptrb.pesempid = pesemp.pesempid 
    Left Join loctrb on pesemptrb.loctrbid = loctrb.loctrbid 
    Where pesemp.fim is null and fco.fcoid <> 9 ) 
    Order by pes.gra 
    

    The table generate by the query has 113 records but when I limit the number of records to 111 it runs without errors. 

    Select pes.* from pes where pes.pesid in 
    (SELECT pesemp.pesid 
    FROM pesemp 
    Left JOIN emp ON pesemp.empid = emp.empid 
    Left JOIN pesempfco ON pesempfco.pesempid = pesemp.pesempid 
    Left JOIN fco ON pesempfco.fcoid = fco.fcoid 
    Left Join pesemptrb on pesemptrb.pesempid = pesemp.pesempid 
    Left Join loctrb on pesemptrb.loctrbid = loctrb.loctrbid 
    Where pesemp.fim is null and fco.fcoid <> 9 ) 
    Order by pes.gra 
    Limit 111 

    Any ideas?

    Tuesday, June 27, 2017 10:37 PM

Answers

  • User753101303 posted

    Hi,

    This is a C# client side exception so showing the client side C# code where it happens might be more helpful. Do you have a stack trace that could give a hint about where it happens.

    You are suing ADO.NET rather than EF ?

    BTW what if you run this SQL query directly into your db ?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 28, 2017 4:48 PM

All replies

  • User753101303 posted

    Hi,

    This is a C# client side exception so showing the client side C# code where it happens might be more helpful. Do you have a stack trace that could give a hint about where it happens.

    You are suing ADO.NET rather than EF ?

    BTW what if you run this SQL query directly into your db ?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 28, 2017 4:48 PM
  • User1144299848 posted

    Hi PatriceSc,

    I am an amateur, so I don't know if I really understand your questions, but they helped me.

    1) I don't know how to find a stack trace. I am going to research it.

    2) I am using EF.

    3) My query directly into DB runs smoth.

    I checked my razor page (I don't know if you were targeting this when you said that the error was a C# client side exception), and I found I was missing the last </td> tag. Fixed that and the problem is gone. Thank you.,

    The page:

    @model IEnumerable<Portal17v5.Models.pes>
    @{
        ViewBag.Title = "_ResultadoPesquisa";
        //Layout = "~/Areas/Pessoal/Views/Shared/_LayoutPessoal.cshtml";
    }
    
    @if (!string.IsNullOrWhiteSpace(ViewBag.msg))
    { <p>Pesquisa: @ViewBag.msg </p> }
    </p>
    <table class="table">
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.foto)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.nom)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.gra)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.nto)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.cpf)
            </th>
            <th></th>
        </tr>
    
        @foreach (var item in Model)
        {
            <tr>
                <td style="width:25%;">
    
                    @if (!string.IsNullOrEmpty(item.foto))
                    { <img src="~/Areas/Pessoal/Fotos/@Url.Content(item.foto)" alt="sem foto" style="width:25%;" /> }
                    else
                    { <img src="~/img/fyret.jpg" style="width:25%;" alt="sem foto" /> }
    
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.nom)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.gra)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.nto)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.cpf, "cpf")
                </td>
                <td>
                    @Html.ActionLink("Editar", "Edit", "Pes", new { id = item.pesid }, null) |
                    @Html.ActionLink("Detalhes", "Details", "Pes", new { id = item.pesid }, null) |
                    @Html.ActionLink("Excluir", "Delete", "Pes", new { id = item.pesid }, null)
                    <br />
                    @Html.ActionLink("Admissão", "AssociaFuncionario", "Funcionario", new { id = item.pesid }, null) |
                    @Html.ActionLink("Gerenciar", "AltDados", "Funcionario", new { id = item.pesid }, null)
                </td> // the missing tag
            </tr>
        }
    
    </table>
    

    Wednesday, June 28, 2017 11:38 PM
  • User753101303 posted

    So when it happens in VS, try to show the "call stack window" : https://msdn.microsoft.com/en-us/library/a3694ts5.aspx

    Even if caused indirectly by your SQL statement, the error happens on the C# client side and by looking at the calls I hope we should be able to understand what is repeatedly called to finally throw this exception.

    Thursday, June 29, 2017 7:36 AM