problems with stackoverflowexception

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zapov

    problems with stackoverflowexception

    Hi!

    I'm having some wierd problems with this exception (error).
    If I use sql commands to insert data into sql server i get
    strange behaviour from my application.

    First I used a single threaded application and used
    Application.DoE vents() when i needed to wait some time.
    (I need to process some external information on events
    so I can't just use Thread.Sleep).
    I need to store some information on regular basis interval
    (about 1 minute) so firstly i used xml to store information.
    But after application executed for some time DataSet used to
    store information would get destroyed (?!) and I would receive
    Object not set to reference error. So I switched to SQL server.
    First choice MSDE. I used stored procedures and executed them
    from application, but application showed strange behaviour and
    would sometimes stop when executing stored procedures for a few
    seconds. Often it would stop and would not continue.
    So I switched to MySQL and text queries. But I started to receive
    StackOverflowEx ception. I got confused and changed application
    so it's not anymore a single threaded application and instead
    of Application.DoE vents() I use Thread.Sleep
    But strangely the Stackoverflowex ception remained.

    In application if instead of executing nonqueries I just return
    from that function program works fine. There is nothing wrong
    with sql part of the code, but I can't get a lock on the problem.
    I'm getting desperate with this problem. Using .NET 1.1 with SP1
    on WinXP SP2.
  • Robert Jordan

    #2
    Re: problems with stackoverflowex ception

    Hi,
    [color=blue]
    > I'm having some wierd problems with this exception (error).
    > If I use sql commands to insert data into sql server i get
    > strange behaviour from my application.
    >
    > First I used a single threaded application and used
    > Application.DoE vents() when i needed to wait some time.
    > (I need to process some external information on events
    > so I can't just use Thread.Sleep).
    > I need to store some information on regular basis interval
    > (about 1 minute) so firstly i used xml to store information.
    > But after application executed for some time DataSet used to
    > store information would get destroyed (?!) and I would receive
    > Object not set to reference error. So I switched to SQL server.
    > First choice MSDE. I used stored procedures and executed them
    > from application, but application showed strange behaviour and
    > would sometimes stop when executing stored procedures for a few
    > seconds. Often it would stop and would not continue.
    > So I switched to MySQL and text queries. But I started to receive
    > StackOverflowEx ception. I got confused and changed application
    > so it's not anymore a single threaded application and instead
    > of Application.DoE vents() I use Thread.Sleep
    > But strangely the Stackoverflowex ception remained.
    >
    > In application if instead of executing nonqueries I just return
    > from that function program works fine. There is nothing wrong
    > with sql part of the code, but I can't get a lock on the problem.
    > I'm getting desperate with this problem. Using .NET 1.1 with SP1
    > on WinXP SP2.[/color]


    I guess the code that calls Application.DoE vents() is reentered,
    like this:

    void Idle() {
    Application.DoE vents();
    }

    void SomeUIEventHand ler(...) {
    Idle();
    }

    Solution: use threads or assure that Application.DoE vents()
    is never reentered.

    bye
    Rob

    ps: don't switch technologies like your pants ;-) Choose
    one and stick with it until it works.

    Comment

    • zapov

      #3
      Re: problems with stackoverflowex ception

      Robert Jordan wrote:[color=blue]
      > Hi,
      >[color=green]
      >> StackOverflowEx ception. I got confused and changed application
      >> so it's not anymore a single threaded application and instead
      >> of Application.DoE vents() I use Thread.Sleep
      >> But strangely the Stackoverflowex ception remained.[/color]
      >
      > I guess the code that calls Application.DoE vents() is reentered,
      > like this:
      >
      > void Idle() {
      > Application.DoE vents();
      > }
      >
      > void SomeUIEventHand ler(...) {
      > Idle();
      > }
      >
      > Solution: use threads or assure that Application.DoE vents()
      > is never reentered.
      >
      > bye
      > Rob
      >
      > ps: don't switch technologies like your pants ;-) Choose
      > one and stick with it until it works.[/color]

      You didn't read my post carefuly. I said I changed application
      so it uses threads and doesn't call app.doevents

      ps. :) Of course. Goal was for MySQL, but I have more experience
      in MSDE, so I tried that first

      Comment

      • Joep

        #4
        Re: problems with stackoverflowex ception

        Whatever it is, something gets executed repeatedly unintended and consumes
        stack on each iteration. It will not be SQL but code. You mention 'about 1
        minute'? That sounds like an iterating thing, doesn't it? Without the actual
        code can't say much more.


        Comment

        • zapov

          #5
          Re: problems with stackoverflowex ception

          Joep wrote:[color=blue]
          > Whatever it is, something gets executed repeatedly unintended and consumes
          > stack on each iteration. It will not be SQL but code. You mention 'about 1
          > minute'? That sounds like an iterating thing, doesn't it? Without the actual
          > code can't say much more.
          >
          >[/color]

          Ok, but the problem is that if I don't use sql app works fine.
          And if I use sql app crashes on first time it uses nonqueries

          Comment

          • zapov

            #6
            Re: problems with stackoverflowex ception

            zapov wrote:[color=blue]
            > Joep wrote:
            >[color=green]
            >> Whatever it is, something gets executed repeatedly unintended and
            >> consumes stack on each iteration. It will not be SQL but code. You
            >> mention 'about 1 minute'? That sounds like an iterating thing, doesn't
            >> it? Without the actual code can't say much more.
            >>
            >>[/color]
            >
            > Ok, but the problem is that if I don't use sql app works fine.
            > And if I use sql app crashes on first time it uses nonqueries[/color]

            Hmmm, how could I check stack to see what's on it?

            Comment

            • Joep

              #7
              Re: problems with stackoverflowex ception

              When you execute the SQL you have some code to process the result, don't
              you? That is what I would look at carefully to start with. Without executing
              SQL no processing of the result happens so my first guess would be that
              processing. It most likely creates instances (direct or indirect) and is
              reentered maybe, some event that gets triggered as part of processing is
              also part of processing. The latter can be checked by adding some
              instrumentation to show the number of iterations thru relevant function(s).






              Comment

              • Joep

                #8
                Re: problems with stackoverflowex ception

                By the way, you also mentioned threading which can also be part of the
                problem if it related to the SQL execution. Without code it's difficult to
                be more precise, it remains theory at best.


                Comment

                • Joep

                  #9
                  Re: problems with stackoverflowex ception

                  ....and...is it reproducable when you run only a single thread?


                  Comment

                  • zapov

                    #10
                    Re: problems with stackoverflowex ception

                    Joep wrote:[color=blue]
                    > ...and...is it reproducable when you run only a single thread?
                    >
                    >[/color]

                    Yes, the same problem appears with a single or multy threaded
                    application. The code is simple, it looks like this


                    public bool WriteUsage(stri ng gdje,int koji)
                    {
                    Monitor.Enter(q ue1);
                    que1.Enqueue(ob j1);
                    int k=0;
                    try
                    {
                    bool da=koji==1;
                    sqlcom.CommandT ext="INSERT INTO Zauzetost
                    VALUES("+gdje+" ,'"+DateTime.No w.ToString()+"' ,'"+da.ToString ()+"')";
                    if(sqlconn.Stat e!=ConnectionSt ate.Open) sqlconn.Open();
                    k=sqlcom.Execut eNonQuery();
                    sqlconn.Close() ;
                    }
                    catch(Exception ex)
                    {
                    Monitor.Exit(qu e1);
                    LogError(ex);
                    return false;
                    }
                    Monitor.Exit(qu e1);
                    return k>0;
                    }

                    I ruled out the sql error because, this code works fine in other
                    applications. But, if I dont insert return true into first line of
                    this procedure, application crashes. :(
                    And no, as you can see, I don't use this part of the code to
                    process information, in fact, parts of the code with select
                    works fine and don't cause errors.

                    Comment

                    • Jon Skeet [C# MVP]

                      #11
                      Re: problems with stackoverflowex ception

                      zapov <zapov@yahoo.co m> wrote:[color=blue]
                      > I'm having some wierd problems with this exception (error).
                      > If I use sql commands to insert data into sql server i get
                      > strange behaviour from my application.[/color]

                      <snip>

                      Could you post a short but complete program which demonstrates the
                      problem?

                      See http://www.pobox.com/~skeet/csharp/complete.html for details of
                      what I mean by that.

                      --
                      Jon Skeet - <skeet@pobox.co m>
                      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                      If replying to the group, please do not mail me too

                      Comment

                      • Joep

                        #12
                        Re: problems with stackoverflowex ception

                        I see nothing wrong here. Without execution all is well, with execution you
                        end up with a stack o'flow, right? So does that apply to all INSERT
                        statements? What happens if you hard code the columns and the values ? Could
                        it be some mismatch between expected value and received value?


                        Comment

                        • zapov

                          #13
                          Re: problems with stackoverflowex ception

                          Joep wrote:[color=blue]
                          > I see nothing wrong here. Without execution all is well, with execution you
                          > end up with a stack o'flow, right? So does that apply to all INSERT
                          > statements? What happens if you hard code the columns and the values ? Could
                          > it be some mismatch between expected value and received value?
                          >
                          >[/color]

                          Strangely, but no :)
                          The problem is that sometimes the code inserts values into database,
                          but when it doesn't exception raises.

                          I tried also using another database and protocol, so I gues it's not
                          drivers fault, or is it? :)
                          I guess, I'll have to try it without WinXP SP2
                          Because when using MSDE program ends up waiting in that code instead
                          of raising stackoverflowex ception.

                          Comment

                          • zapov

                            #14
                            Re: problems with stackoverflowex ception

                            Jon Skeet [C# MVP] wrote:[color=blue]
                            > <snip>
                            >
                            > Could you post a short but complete program which demonstrates the
                            > problem?
                            >
                            > See http://www.pobox.com/~skeet/csharp/complete.html for details of
                            > what I mean by that.
                            >[/color]

                            Hm, no.
                            Event is raised by serial communcation with microcontroler so
                            it can be runned only on specific machine.

                            But you gave me a good idea, and if program ends up doing the same thing
                            I think I could try to post code tomorrow

                            Comment

                            • Willy Denoyette [MVP]

                              #15
                              Re: problems with stackoverflowex ception

                              The problem here is that you show us some code without any evidence that:
                              - the StackOverFlow exception is thrown by this part (that is, you don't
                              show us a stack trace)
                              - the "stack overflow" itself is due to this part of code, note that the
                              stack is shared by all code running on a thread, so it's perfectly possible
                              for one (badly behaving) method to consumes so much stack space, that
                              another (correctly behaving) method, fails because there's not anough free
                              stack space left.

                              Willy.


                              "zapov" <zapov@yahoo.co m> wrote in message
                              news:ckt20b$i8p $1@news1.xnet.h r...[color=blue]
                              > Joep wrote:[color=green]
                              >> ...and...is it reproducable when you run only a single thread?[/color]
                              >
                              > Yes, the same problem appears with a single or multy threaded
                              > application. The code is simple, it looks like this
                              >
                              >
                              > public bool WriteUsage(stri ng gdje,int koji)
                              > {
                              > Monitor.Enter(q ue1);
                              > que1.Enqueue(ob j1);
                              > int k=0;
                              > try
                              > {
                              > bool da=koji==1;
                              > sqlcom.CommandT ext="INSERT INTO Zauzetost
                              > VALUES("+gdje+" ,'"+DateTime.No w.ToString()+"' ,'"+da.ToString ()+"')";
                              > if(sqlconn.Stat e!=ConnectionSt ate.Open) sqlconn.Open();
                              > k=sqlcom.Execut eNonQuery();
                              > sqlconn.Close() ;
                              > }
                              > catch(Exception ex)
                              > {
                              > Monitor.Exit(qu e1);
                              > LogError(ex);
                              > return false;
                              > }
                              > Monitor.Exit(qu e1);
                              > return k>0;
                              > }
                              >
                              > I ruled out the sql error because, this code works fine in other
                              > applications. But, if I dont insert return true into first line of
                              > this procedure, application crashes. :(
                              > And no, as you can see, I don't use this part of the code to
                              > process information, in fact, parts of the code with select
                              > works fine and don't cause errors.[/color]


                              Comment

                              Working...