Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Mysterious NullReferenceException

Mysterious NullReferenceException

Scheduled Pinned Locked Moved ASP.NET
databasecsharpasp-netoraclehelp
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Plunging_Falcon
    wrote on last edited by
    #1

    Hi all, I have a very weird problem that i have been battling with (or pushing aside...) for months. I wrote an asp.net application that connects to an Oracle db using stored procedures. The procedures seem to work, the code seems to work and when I run it MOST of the time it runs great. But, sometimes (say 1 time out of 10 or 15) it crashes with the false accusation of a nullreference exception. If I go back and perform it again - it works. I added try/catch statements for this exception, and it has reduced their number (if I catch it and do nothing it works!!!), but it still happens and i'm pretty clueless on what to do. I suspect this might be some db problem, maybe i'm not closing connections right, but i don't know what it might be. Here are the 2 methods i use to access the database: protected void execSQLsp(string newCommand, OracleParameter[] parr) { OracleDataReader dr = null; OracleCommand oraCommand = null; try { oraConn.Open(); oraCommand = new OracleCommand(newCommand, oraConn); oraCommand.CommandType = CommandType.StoredProcedure; if (parr != null) for (int i=0; i Second one handles cursor containing queries: `protected OracleDataReader execSQLcurr(string newCommand, OracleParameter[] parr) { OracleCommand oraCommand = null; OracleDataReader dr = null; try { oraConn.Open(); oraCommand = new OracleCommand(newCommand, oraConn); oraCommand.CommandType = CommandType.StoredProcedure; if (parr != null) for (int i=0; i`

    A G 2 Replies Last reply
    0
    • P Plunging_Falcon

      Hi all, I have a very weird problem that i have been battling with (or pushing aside...) for months. I wrote an asp.net application that connects to an Oracle db using stored procedures. The procedures seem to work, the code seems to work and when I run it MOST of the time it runs great. But, sometimes (say 1 time out of 10 or 15) it crashes with the false accusation of a nullreference exception. If I go back and perform it again - it works. I added try/catch statements for this exception, and it has reduced their number (if I catch it and do nothing it works!!!), but it still happens and i'm pretty clueless on what to do. I suspect this might be some db problem, maybe i'm not closing connections right, but i don't know what it might be. Here are the 2 methods i use to access the database: protected void execSQLsp(string newCommand, OracleParameter[] parr) { OracleDataReader dr = null; OracleCommand oraCommand = null; try { oraConn.Open(); oraCommand = new OracleCommand(newCommand, oraConn); oraCommand.CommandType = CommandType.StoredProcedure; if (parr != null) for (int i=0; i Second one handles cursor containing queries: `protected OracleDataReader execSQLcurr(string newCommand, OracleParameter[] parr) { OracleCommand oraCommand = null; OracleDataReader dr = null; try { oraConn.Open(); oraCommand = new OracleCommand(newCommand, oraConn); oraCommand.CommandType = CommandType.StoredProcedure; if (parr != null) for (int i=0; i`

      A Offline
      A Offline
      Alsvha
      wrote on last edited by
      #2

      I would think it indeed is a problem with the datareader. However - my limited experience in the field makes me say this with some restraints (I'm sure somebody more knowlegdable will come along and say I'm wrong anyway :D) As far as I understand it datareaders keep connection to the database, and if you fail to close them proberly, you could end up with one reader blocking another reader, in which case you get a timeout and get a nothing reader, which would give you your nullreference when trying to use this. I would suspect it might be the latter of your two methods where you return "dr". Personall - I'd rewrite the method so it doens't return a datareader, but instead wrap it into a DataSet and then return that. However - that is how I'd start debugging this error, but again - I'm limited in experience (I've only programmed professional and asp.net for 10months). --------------------------- 127.0.0.1 - Sweet 127.0.0.1

      P 1 Reply Last reply
      0
      • P Plunging_Falcon

        Hi all, I have a very weird problem that i have been battling with (or pushing aside...) for months. I wrote an asp.net application that connects to an Oracle db using stored procedures. The procedures seem to work, the code seems to work and when I run it MOST of the time it runs great. But, sometimes (say 1 time out of 10 or 15) it crashes with the false accusation of a nullreference exception. If I go back and perform it again - it works. I added try/catch statements for this exception, and it has reduced their number (if I catch it and do nothing it works!!!), but it still happens and i'm pretty clueless on what to do. I suspect this might be some db problem, maybe i'm not closing connections right, but i don't know what it might be. Here are the 2 methods i use to access the database: protected void execSQLsp(string newCommand, OracleParameter[] parr) { OracleDataReader dr = null; OracleCommand oraCommand = null; try { oraConn.Open(); oraCommand = new OracleCommand(newCommand, oraConn); oraCommand.CommandType = CommandType.StoredProcedure; if (parr != null) for (int i=0; i Second one handles cursor containing queries: `protected OracleDataReader execSQLcurr(string newCommand, OracleParameter[] parr) { OracleCommand oraCommand = null; OracleDataReader dr = null; try { oraConn.Open(); oraCommand = new OracleCommand(newCommand, oraConn); oraCommand.CommandType = CommandType.StoredProcedure; if (parr != null) for (int i=0; i`

        G Offline
        G Offline
        Gavin Jeffrey
        wrote on last edited by
        #3

        if you remove the try catches on what line does it say the error is?

        P 1 Reply Last reply
        0
        • G Gavin Jeffrey

          if you remove the try catches on what line does it say the error is?

          P Offline
          P Offline
          Plunging_Falcon
          wrote on last edited by
          #4

          If I remove the try/catch it fails when I try to execute the query.

          1 Reply Last reply
          0
          • A Alsvha

            I would think it indeed is a problem with the datareader. However - my limited experience in the field makes me say this with some restraints (I'm sure somebody more knowlegdable will come along and say I'm wrong anyway :D) As far as I understand it datareaders keep connection to the database, and if you fail to close them proberly, you could end up with one reader blocking another reader, in which case you get a timeout and get a nothing reader, which would give you your nullreference when trying to use this. I would suspect it might be the latter of your two methods where you return "dr". Personall - I'd rewrite the method so it doens't return a datareader, but instead wrap it into a DataSet and then return that. However - that is how I'd start debugging this error, but again - I'm limited in experience (I've only programmed professional and asp.net for 10months). --------------------------- 127.0.0.1 - Sweet 127.0.0.1

            P Offline
            P Offline
            Plunging_Falcon
            wrote on last edited by
            #5

            Hey, Thanks for the reply. So you think it's best to close the datareader as soon as possible? Basically, I close the datareader write after that procedure (after transfering data to a sortedlist) by executing the following: dr.Close(); dr.Dispose(); dr = null; if (oraConn.State != ConnectionState.Closed) oraConn.Close();

            A 1 Reply Last reply
            0
            • P Plunging_Falcon

              Hey, Thanks for the reply. So you think it's best to close the datareader as soon as possible? Basically, I close the datareader write after that procedure (after transfering data to a sortedlist) by executing the following: dr.Close(); dr.Dispose(); dr = null; if (oraConn.State != ConnectionState.Closed) oraConn.Close();

              A Offline
              A Offline
              Alsvha
              wrote on last edited by
              #6

              It is always best to close the datareader as soon as possible, from what I've experienced and read. Update datareaders lock the data it access, which could deadlock with you trying to read from it if either reader is open "to long". A method to try and debug this possiblity would be to instead of acutally returning the datareader, then try to return some "dummy" data, and close the datareader in the same method. Then try to run the program X number of times to see if this helps on the issue. Also - I don't know if you have access to the database, but you could try to look at how many open connections there is during run-time, to see if the number is higher then expected, which could hint at some readers being open "to long" or even not closed proberly. --------------------------- 127.0.0.1 - Sweet 127.0.0.1

              P 1 Reply Last reply
              0
              • A Alsvha

                It is always best to close the datareader as soon as possible, from what I've experienced and read. Update datareaders lock the data it access, which could deadlock with you trying to read from it if either reader is open "to long". A method to try and debug this possiblity would be to instead of acutally returning the datareader, then try to return some "dummy" data, and close the datareader in the same method. Then try to run the program X number of times to see if this helps on the issue. Also - I don't know if you have access to the database, but you could try to look at how many open connections there is during run-time, to see if the number is higher then expected, which could hint at some readers being open "to long" or even not closed proberly. --------------------------- 127.0.0.1 - Sweet 127.0.0.1

                P Offline
                P Offline
                Plunging_Falcon
                wrote on last edited by
                #7

                OK, sounds like a way. Thanks for your help.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups