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. General Programming
  3. C#
  4. [SOLVED]: Not Getting Proper Output From Compiled EXE File

[SOLVED]: Not Getting Proper Output From Compiled EXE File

Scheduled Pinned Locked Moved C#
helpvisual-studio
23 Posts 9 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.
  • B Bastar Media

    Hello there, WORK: I am working on a project, in which the output of some methods create a excel sheet. PROBLEM: When I run the project from IDE, the excel file is created properly and with all data from List. But, when its run from the compiled EXE file, I am getting no output in the excel file. Please help.

    P Offline
    P Offline
    Pete OHanlon
    wrote on last edited by
    #2

    Wow. You're expecting a lot from us here. No code, only a description of the problem. I'm not sure you're going to get much more help than this I'm afraid.

    B 1 Reply Last reply
    0
    • B Bastar Media

      Hello there, WORK: I am working on a project, in which the output of some methods create a excel sheet. PROBLEM: When I run the project from IDE, the excel file is created properly and with all data from List. But, when its run from the compiled EXE file, I am getting no output in the excel file. Please help.

      G Offline
      G Offline
      GuyThiebaut
      wrote on last edited by
      #3

      Have you recompiled your project making sure that 'release' is selected in the configuration dropdown? It could be that you have 'debug' selected and when you run from the IDE you are running in debug mode but never recompiling in release mode.

      “That which can be asserted without evidence, can be dismissed without evidence.”

      ― Christopher Hitchens

      B 1 Reply Last reply
      0
      • P Pete OHanlon

        Wow. You're expecting a lot from us here. No code, only a description of the problem. I'm not sure you're going to get much more help than this I'm afraid.

        B Offline
        B Offline
        Bastar Media
        wrote on last edited by
        #4

        Hearty Sorry, Here is the code:

        public void WardList()
        {
        #region Load Values...
        int count = 1;
        List WWList = new List();
        Engine E = new Engine();
        SQLiteCommand CMD = new SQLiteCommand(E.SelectSQL("WARDS") + " ORDER BY [WARDNUMBER];", E.Conn);
        SQLiteDataReader RDR = CMD.ExecuteReader();

                while (RDR.Read())
                {
                    WardWise WW = new WardWise();
                    WW.Serial = count;
                    WW.WardNumber = Convert.ToInt32(RDR\["WARDNUMBER"\]);
                    WW.WardCount = WardCount(WW.WardNumber);
                    WW.Name = RDR\["NAME"\].ToString();
                    WW.Manager = RDR\["MANAGER"\].ToString();
                    WW.TotalTax = WardExists(WW.WardNumber) ? WardWiseTax(WW.WardNumber) : 0;
                    WW.TotalPaid = WardExists(WW.WardNumber) ? WardWiseTax(WW.WardNumber, false) : 0;
                    WW.Balance = WW.TotalTax - WW.TotalPaid;
                    count++;
                    WWList.Add(WW);
                }
                #endregion
        
                using (ExcelPackage EP = new ExcelPackage(Masters, Template))
                {
                    double hook = 8;
                    ExcelWorksheet Sheet = EP.Workbook.Worksheets\["AWW"\];
        
                    foreach (WardWise WW in WWList)
                    {
                        Sheet.Cells\["A" + hook\].Value = WW.Serial;
                        Sheet.Cells\["B" + hook\].Value = WW.WardNumber + " \[" + WW.WardCount + "\]";
                        Sheet.Cells\["C" + hook\].Value = WW.Name;
                        Sheet.Cells\["D" + hook\].Value = WW.Manager;
                        Sheet.Cells\["E" + hook\].Value = WW.TotalTax;
                        Sheet.Cells\["F" + hook\].Value = WW.TotalPaid;
                        Sheet.Cells\["G" + hook\].Formula = ("E" + hook) + "-" + ("F" + hook);
                        hook++;
                    }
                    Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Top.Style =
                        Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Bottom.Style =
                        Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Left.Style =
                        Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Right.Style = ExcelBorderStyle.Thin;
        
                    Sheet.Cells\["G" + (hook + 1)\].Formula = string.Format("SUM(G8:G{0})", hook - 1);
                    Sheet.Cells\["G" + (hook + 1)\].Style.Font.Bold = true;
                    Sheet.Cells\["G" + (hook + 1)\].Style.Border.Top.Style =
                        Sheet.Cells\["G" + (h
        
        1 Reply Last reply
        0
        • G GuyThiebaut

          Have you recompiled your project making sure that 'release' is selected in the configuration dropdown? It could be that you have 'debug' selected and when you run from the IDE you are running in debug mode but never recompiling in release mode.

          “That which can be asserted without evidence, can be dismissed without evidence.”

          ― Christopher Hitchens

          B Offline
          B Offline
          Bastar Media
          wrote on last edited by
          #5

          Hi GuyThiebaut, I tried that too, but getting no success.

          1 Reply Last reply
          0
          • B Bastar Media

            Hello there, WORK: I am working on a project, in which the output of some methods create a excel sheet. PROBLEM: When I run the project from IDE, the excel file is created properly and with all data from List. But, when its run from the compiled EXE file, I am getting no output in the excel file. Please help.

            B Offline
            B Offline
            Bastar Media
            wrote on last edited by
            #6

            Hearty Sorry for not posting the code: Here is the code:

            public void WardList()
            {
            #region Load Values...
            int count = 1;
            List WWList = new List();
            Engine E = new Engine();
            SQLiteCommand CMD = new SQLiteCommand(E.SelectSQL("WARDS") + " ORDER BY [WARDNUMBER];", E.Conn);
            SQLiteDataReader RDR = CMD.ExecuteReader();

                    while (RDR.Read())
                    {
                        WardWise WW = new WardWise();
                        WW.Serial = count;
                        WW.WardNumber = Convert.ToInt32(RDR\["WARDNUMBER"\]);
                        WW.WardCount = WardCount(WW.WardNumber);
                        WW.Name = RDR\["NAME"\].ToString();
                        WW.Manager = RDR\["MANAGER"\].ToString();
                        WW.TotalTax = WardExists(WW.WardNumber) ? WardWiseTax(WW.WardNumber) : 0;
                        WW.TotalPaid = WardExists(WW.WardNumber) ? WardWiseTax(WW.WardNumber, false) : 0;
                        WW.Balance = WW.TotalTax - WW.TotalPaid;
                        count++;
                        WWList.Add(WW);
                    }
                    #endregion
            
                    using (ExcelPackage EP = new ExcelPackage(Masters, Template))
                    {
                        double hook = 8;
                        ExcelWorksheet Sheet = EP.Workbook.Worksheets\["AWW"\];
            
                        foreach (WardWise WW in WWList)
                        {
                            Sheet.Cells\["A" + hook\].Value = WW.Serial;
                            Sheet.Cells\["B" + hook\].Value = WW.WardNumber + " \[" + WW.WardCount + "\]";
                            Sheet.Cells\["C" + hook\].Value = WW.Name;
                            Sheet.Cells\["D" + hook\].Value = WW.Manager;
                            Sheet.Cells\["E" + hook\].Value = WW.TotalTax;
                            Sheet.Cells\["F" + hook\].Value = WW.TotalPaid;
                            Sheet.Cells\["G" + hook\].Formula = ("E" + hook) + "-" + ("F" + hook);
                            hook++;
                        }
                        Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Top.Style =
                            Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Bottom.Style =
                            Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Left.Style =
                            Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Right.Style = ExcelBorderStyle.Thin;
            
                        Sheet.Cells\["G" + (hook + 1)\].Formula = string.Format("SUM(G8:G{0})", hook - 1);
                        Sheet.Cells\["G" + (hook + 1)\].Style.Font.Bold = true;
                        Sheet.Cells\["G" + (hook + 1)\].Style.Border.Top.Style =
            
            L 1 Reply Last reply
            0
            • B Bastar Media

              Hello there, WORK: I am working on a project, in which the output of some methods create a excel sheet. PROBLEM: When I run the project from IDE, the excel file is created properly and with all data from List. But, when its run from the compiled EXE file, I am getting no output in the excel file. Please help.

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #7

              Start by looking at the input and output files: are you using absolute paths? Relative paths? Are they all looking at the same files? What are the folders like - do they have suitable permissions, if they aren't the same? Are the debug and release versions running on the same computer? Under the same user? What happens if you execute the debug version directly in the same way you did with the release? Do you get any error messages? Are you swallowing any exceptions? You need to get information on exactly what is happening - we can't run your code in isolation! :laugh:

              Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              B U 2 Replies Last reply
              0
              • B Bastar Media

                Hearty Sorry for not posting the code: Here is the code:

                public void WardList()
                {
                #region Load Values...
                int count = 1;
                List WWList = new List();
                Engine E = new Engine();
                SQLiteCommand CMD = new SQLiteCommand(E.SelectSQL("WARDS") + " ORDER BY [WARDNUMBER];", E.Conn);
                SQLiteDataReader RDR = CMD.ExecuteReader();

                        while (RDR.Read())
                        {
                            WardWise WW = new WardWise();
                            WW.Serial = count;
                            WW.WardNumber = Convert.ToInt32(RDR\["WARDNUMBER"\]);
                            WW.WardCount = WardCount(WW.WardNumber);
                            WW.Name = RDR\["NAME"\].ToString();
                            WW.Manager = RDR\["MANAGER"\].ToString();
                            WW.TotalTax = WardExists(WW.WardNumber) ? WardWiseTax(WW.WardNumber) : 0;
                            WW.TotalPaid = WardExists(WW.WardNumber) ? WardWiseTax(WW.WardNumber, false) : 0;
                            WW.Balance = WW.TotalTax - WW.TotalPaid;
                            count++;
                            WWList.Add(WW);
                        }
                        #endregion
                
                        using (ExcelPackage EP = new ExcelPackage(Masters, Template))
                        {
                            double hook = 8;
                            ExcelWorksheet Sheet = EP.Workbook.Worksheets\["AWW"\];
                
                            foreach (WardWise WW in WWList)
                            {
                                Sheet.Cells\["A" + hook\].Value = WW.Serial;
                                Sheet.Cells\["B" + hook\].Value = WW.WardNumber + " \[" + WW.WardCount + "\]";
                                Sheet.Cells\["C" + hook\].Value = WW.Name;
                                Sheet.Cells\["D" + hook\].Value = WW.Manager;
                                Sheet.Cells\["E" + hook\].Value = WW.TotalTax;
                                Sheet.Cells\["F" + hook\].Value = WW.TotalPaid;
                                Sheet.Cells\["G" + hook\].Formula = ("E" + hook) + "-" + ("F" + hook);
                                hook++;
                            }
                            Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Top.Style =
                                Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Bottom.Style =
                                Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Left.Style =
                                Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                
                            Sheet.Cells\["G" + (hook + 1)\].Formula = string.Format("SUM(G8:G{0})", hook - 1);
                            Sheet.Cells\["G" + (hook + 1)\].Style.Font.Bold = true;
                            Sheet.Cells\["G" + (hook + 1)\].Style.Border.Top.Style =
                
                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #8

                That is just a code dump, and gives no more clue that your original question. You need to explain where the problem occurs, since we have no idea how this code is supposed to work.

                1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  Start by looking at the input and output files: are you using absolute paths? Relative paths? Are they all looking at the same files? What are the folders like - do they have suitable permissions, if they aren't the same? Are the debug and release versions running on the same computer? Under the same user? What happens if you execute the debug version directly in the same way you did with the release? Do you get any error messages? Are you swallowing any exceptions? You need to get information on exactly what is happening - we can't run your code in isolation! :laugh:

                  Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                  B Offline
                  B Offline
                  Bastar Media
                  wrote on last edited by
                  #9

                  Hi OriginalGriff, The code for input and output files is

                  private static readonly string TemplatesFile =
                  Path.Combine(Directories.CurrentDirectory, "Reports", "ReportsTemplate.xlsx");
                  private static readonly string MastersFile =
                  Path.Combine(Directories.CurrentDirectory, "Reports", "Master.xlsx");
                  private static FileInfo Template = new FileInfo(TemplatesFile);
                  private static FileInfo Masters;

                  The folders have suitable permissions. Yes, Debug and Release version are on the same computer, under same user. When I run the EXE file I am not getting any output on both Debug and Release versions, but getting nice excel report when I run it from the IDE. I am getting no errors. But, in the output window of the IDE, I am getting lots of First Chance Exceptions like this:

                  A first chance exception of type 'System.ObjectDisposedException' occurred in System.Data.SQLite.dll

                  Even though, I am getting a nice excel report. But not from EXE file. Regards.

                  OriginalGriffO G M 3 Replies Last reply
                  0
                  • B Bastar Media

                    Hi OriginalGriff, The code for input and output files is

                    private static readonly string TemplatesFile =
                    Path.Combine(Directories.CurrentDirectory, "Reports", "ReportsTemplate.xlsx");
                    private static readonly string MastersFile =
                    Path.Combine(Directories.CurrentDirectory, "Reports", "Master.xlsx");
                    private static FileInfo Template = new FileInfo(TemplatesFile);
                    private static FileInfo Masters;

                    The folders have suitable permissions. Yes, Debug and Release version are on the same computer, under same user. When I run the EXE file I am not getting any output on both Debug and Release versions, but getting nice excel report when I run it from the IDE. I am getting no errors. But, in the output window of the IDE, I am getting lots of First Chance Exceptions like this:

                    A first chance exception of type 'System.ObjectDisposedException' occurred in System.Data.SQLite.dll

                    Even though, I am getting a nice excel report. But not from EXE file. Regards.

                    OriginalGriffO Offline
                    OriginalGriffO Offline
                    OriginalGriff
                    wrote on last edited by
                    #10

                    You are using relative paths - relative to the current directory, which will default to the folder the app is run from - so check that you are looking in the right folder when you run the code. And I'd look in the debugger at where the exceptions are happening and why - it may be that they are relevant to your problem, and it works because the debugger is trapping the exception and letting you know it occurred. In the "undebugged" version, they may be stopping your code running. If you look on the VS Debug menu, you can tell it to break on all exceptions, caught or not.

                    Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                    1 Reply Last reply
                    0
                    • B Bastar Media

                      Hi OriginalGriff, The code for input and output files is

                      private static readonly string TemplatesFile =
                      Path.Combine(Directories.CurrentDirectory, "Reports", "ReportsTemplate.xlsx");
                      private static readonly string MastersFile =
                      Path.Combine(Directories.CurrentDirectory, "Reports", "Master.xlsx");
                      private static FileInfo Template = new FileInfo(TemplatesFile);
                      private static FileInfo Masters;

                      The folders have suitable permissions. Yes, Debug and Release version are on the same computer, under same user. When I run the EXE file I am not getting any output on both Debug and Release versions, but getting nice excel report when I run it from the IDE. I am getting no errors. But, in the output window of the IDE, I am getting lots of First Chance Exceptions like this:

                      A first chance exception of type 'System.ObjectDisposedException' occurred in System.Data.SQLite.dll

                      Even though, I am getting a nice excel report. But not from EXE file. Regards.

                      G Offline
                      G Offline
                      Gonzoox
                      wrote on last edited by
                      #11

                      I'd recommend that you debug it line by line and check if everything is happening as expected, is line 1 getting the values? how about line 2? 3? and so on. is every object instanced correctly? must of the times something really small is what is causing the problem. When you execute the code inside visual studio, the application runs from the debug/release folder, are you executing it from the same location? or you copied the exe to a different folder? could it be is the paths you're using to read and write are not returning a valid path?

                      I want to die like my grandfather- asleep, not like the passengers in his car, screaming!

                      M B 2 Replies Last reply
                      0
                      • G Gonzoox

                        I'd recommend that you debug it line by line and check if everything is happening as expected, is line 1 getting the values? how about line 2? 3? and so on. is every object instanced correctly? must of the times something really small is what is causing the problem. When you execute the code inside visual studio, the application runs from the debug/release folder, are you executing it from the same location? or you copied the exe to a different folder? could it be is the paths you're using to read and write are not returning a valid path?

                        I want to die like my grandfather- asleep, not like the passengers in his car, screaming!

                        M Offline
                        M Offline
                        Matt T Heffron
                        wrote on last edited by
                        #12

                        This isn't going to help since he states that the program works as intended when run under the IDE, which of course, is what he'd be doing in order to debug.

                        "Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed." - G.K. Chesterton

                        1 Reply Last reply
                        0
                        • B Bastar Media

                          Hi OriginalGriff, The code for input and output files is

                          private static readonly string TemplatesFile =
                          Path.Combine(Directories.CurrentDirectory, "Reports", "ReportsTemplate.xlsx");
                          private static readonly string MastersFile =
                          Path.Combine(Directories.CurrentDirectory, "Reports", "Master.xlsx");
                          private static FileInfo Template = new FileInfo(TemplatesFile);
                          private static FileInfo Masters;

                          The folders have suitable permissions. Yes, Debug and Release version are on the same computer, under same user. When I run the EXE file I am not getting any output on both Debug and Release versions, but getting nice excel report when I run it from the IDE. I am getting no errors. But, in the output window of the IDE, I am getting lots of First Chance Exceptions like this:

                          A first chance exception of type 'System.ObjectDisposedException' occurred in System.Data.SQLite.dll

                          Even though, I am getting a nice excel report. But not from EXE file. Regards.

                          M Offline
                          M Offline
                          Matt T Heffron
                          wrote on last edited by
                          #13

                          This is beginning to look like a Heisenbug[^] ;)

                          "Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed." - G.K. Chesterton

                          1 Reply Last reply
                          0
                          • G Gonzoox

                            I'd recommend that you debug it line by line and check if everything is happening as expected, is line 1 getting the values? how about line 2? 3? and so on. is every object instanced correctly? must of the times something really small is what is causing the problem. When you execute the code inside visual studio, the application runs from the debug/release folder, are you executing it from the same location? or you copied the exe to a different folder? could it be is the paths you're using to read and write are not returning a valid path?

                            I want to die like my grandfather- asleep, not like the passengers in his car, screaming!

                            B Offline
                            B Offline
                            Bastar Media
                            wrote on last edited by
                            #14

                            Hi Gonzoox, Thanks for the reply. Yes, I had executed and executing the program from the same folder as it was created by the IDE. Moreover, debugging line by line, I am getting proper watch values on each variables. Even though, I will debug it once more as you said. Thanks.

                            1 Reply Last reply
                            0
                            • B Bastar Media

                              Hello there, WORK: I am working on a project, in which the output of some methods create a excel sheet. PROBLEM: When I run the project from IDE, the excel file is created properly and with all data from List. But, when its run from the compiled EXE file, I am getting no output in the excel file. Please help.

                              W Offline
                              W Offline
                              Wendelius
                              wrote on last edited by
                              #15

                              As others have already said, more info would be needed in order to solve the problem. However, I understand the difficulty since the project works in IDE but not as an executable. So what I suggest is that you add some kind of 'messaging' into the code. It could be writing a log file or something similar or simply just show message boxes. Add these messages to the code and run the exe. This should give you better understanding about the execution. Try to add relevant info into the messages such as working directory or the full paths of the file names etc. With the messages you see more easily what happens and what code is reached and what is not.

                              B 2 Replies Last reply
                              0
                              • W Wendelius

                                As others have already said, more info would be needed in order to solve the problem. However, I understand the difficulty since the project works in IDE but not as an executable. So what I suggest is that you add some kind of 'messaging' into the code. It could be writing a log file or something similar or simply just show message boxes. Add these messages to the code and run the exe. This should give you better understanding about the execution. Try to add relevant info into the messages such as working directory or the full paths of the file names etc. With the messages you see more easily what happens and what code is reached and what is not.

                                B Offline
                                B Offline
                                Bastar Media
                                wrote on last edited by
                                #16

                                Hi Mika, As you said I designed a logfile stream writer and now I got my log file full of these two errors:

                                ERROR: Cannot access a disposed object.
                                Object name: 'SQLiteConnection'. TARGET: Void CheckDisposed() STACK TRACE: at System.Data.SQLite.SQLiteConnection.CheckDisposed()
                                at System.Data.SQLite.SQLiteConnection.get_State()
                                at System.Data.SQLite.SQLiteDataReader.CheckClosed()
                                at System.Data.SQLite.SQLiteDataReader.Read()
                                at PTMS.Classes.Reports.Reporting.WardWiseTax(Int32 WardNumber) in Reporting.cs:line 209
                                19/09/2015 12:18:39 PM : ERROR: Cannot access a disposed object.
                                Object name: 'SQLiteConnection'. TARGET: Void CheckDisposed() STACK TRACE: at System.Data.SQLite.SQLiteConnection.CheckDisposed()
                                at System.Data.SQLite.SQLiteConnection.get_State()
                                at System.Data.SQLite.SQLiteDataReader.CheckClosed()
                                at System.Data.SQLite.SQLiteDataReader.Read()
                                at PTMS.Classes.Reports.Reporting.WardWiseTax(Int32 WardNumber, Boolean TotalPaid) in Reporting.cs:line 231

                                And here is the code where I am getting those errors:

                                private double WardWiseTax(Int32 WardNumber)
                                {
                                double TT = 0;
                                try
                                {
                                Engine E = new Engine();
                                SQLiteCommand CUSTCMD = new SQLiteCommand(E.SelectSQL("CUSTOMERS", "WARDNUMBER"), E.Conn);
                                CUSTCMD.Parameters.AddWithValue("WARDNUMBER", WardNumber);
                                SQLiteDataReader CUSTRDR = CUSTCMD.ExecuteReader();
                                Calculate CT = new Calculate();

                                            while (CUSTRDR.Read()) // Here is the error (209)
                                                TT += CT.LedgerBalance(CUSTRDR\["DEMAND"\].ToString())\[1\];
                                
                                            CUSTCMD.Dispose();
                                            CUSTRDR.Dispose();
                                            CT.Dispose();
                                
                                            return TT;
                                        }
                                        catch (Exception ex) { LogEvent.WriteErrorLog(ex); return 0; }
                                    }
                                    private double WardWiseTax(Int32 WardNumber, bool TotalPaid)
                                    {
                                        double TT = 0;
                                        try
                                        {
                                            Engine E = new Engine();
                                            SQLiteCommand CUSTCMD = new SQLiteCommand(E.SelectSQL("CUSTOMERS", "WARDNUMBER"), E.Conn);
                                            CUSTCMD.Parameters.AddWithValue("WARDNUMBER", WardNumber);
                                            SQLiteDataReader CUSTRDR = CUSTCMD.ExecuteReader();
                                            Calculate CT = new Calculate();
                                
                                            while (CUSTRDR.Read()) // Here is the error (231)
                                            {
                                                TT += CT.Le
                                
                                W 1 Reply Last reply
                                0
                                • B Bastar Media

                                  Hi Mika, As you said I designed a logfile stream writer and now I got my log file full of these two errors:

                                  ERROR: Cannot access a disposed object.
                                  Object name: 'SQLiteConnection'. TARGET: Void CheckDisposed() STACK TRACE: at System.Data.SQLite.SQLiteConnection.CheckDisposed()
                                  at System.Data.SQLite.SQLiteConnection.get_State()
                                  at System.Data.SQLite.SQLiteDataReader.CheckClosed()
                                  at System.Data.SQLite.SQLiteDataReader.Read()
                                  at PTMS.Classes.Reports.Reporting.WardWiseTax(Int32 WardNumber) in Reporting.cs:line 209
                                  19/09/2015 12:18:39 PM : ERROR: Cannot access a disposed object.
                                  Object name: 'SQLiteConnection'. TARGET: Void CheckDisposed() STACK TRACE: at System.Data.SQLite.SQLiteConnection.CheckDisposed()
                                  at System.Data.SQLite.SQLiteConnection.get_State()
                                  at System.Data.SQLite.SQLiteDataReader.CheckClosed()
                                  at System.Data.SQLite.SQLiteDataReader.Read()
                                  at PTMS.Classes.Reports.Reporting.WardWiseTax(Int32 WardNumber, Boolean TotalPaid) in Reporting.cs:line 231

                                  And here is the code where I am getting those errors:

                                  private double WardWiseTax(Int32 WardNumber)
                                  {
                                  double TT = 0;
                                  try
                                  {
                                  Engine E = new Engine();
                                  SQLiteCommand CUSTCMD = new SQLiteCommand(E.SelectSQL("CUSTOMERS", "WARDNUMBER"), E.Conn);
                                  CUSTCMD.Parameters.AddWithValue("WARDNUMBER", WardNumber);
                                  SQLiteDataReader CUSTRDR = CUSTCMD.ExecuteReader();
                                  Calculate CT = new Calculate();

                                              while (CUSTRDR.Read()) // Here is the error (209)
                                                  TT += CT.LedgerBalance(CUSTRDR\["DEMAND"\].ToString())\[1\];
                                  
                                              CUSTCMD.Dispose();
                                              CUSTRDR.Dispose();
                                              CT.Dispose();
                                  
                                              return TT;
                                          }
                                          catch (Exception ex) { LogEvent.WriteErrorLog(ex); return 0; }
                                      }
                                      private double WardWiseTax(Int32 WardNumber, bool TotalPaid)
                                      {
                                          double TT = 0;
                                          try
                                          {
                                              Engine E = new Engine();
                                              SQLiteCommand CUSTCMD = new SQLiteCommand(E.SelectSQL("CUSTOMERS", "WARDNUMBER"), E.Conn);
                                              CUSTCMD.Parameters.AddWithValue("WARDNUMBER", WardNumber);
                                              SQLiteDataReader CUSTRDR = CUSTCMD.ExecuteReader();
                                              Calculate CT = new Calculate();
                                  
                                              while (CUSTRDR.Read()) // Here is the error (231)
                                              {
                                                  TT += CT.Le
                                  
                                  W Offline
                                  W Offline
                                  Wendelius
                                  wrote on last edited by
                                  #17

                                  As far as I can see the problem is that the connection is stored in another class, perhaps a static one. Based on this any method can dispose the connection and you would see this as a problem in the next call when the disposed connection is trying to be used. So probably the dispose happens elsewhere. To correct this you would need to do a little bit of a re-design. I've touched this problem in Properly executing database operations[^]. Have a look at the initial version and differences in version 2. I think that clarifies the situation.

                                  B 1 Reply Last reply
                                  0
                                  • W Wendelius

                                    As others have already said, more info would be needed in order to solve the problem. However, I understand the difficulty since the project works in IDE but not as an executable. So what I suggest is that you add some kind of 'messaging' into the code. It could be writing a log file or something similar or simply just show message boxes. Add these messages to the code and run the exe. This should give you better understanding about the execution. Try to add relevant info into the messages such as working directory or the full paths of the file names etc. With the messages you see more easily what happens and what code is reached and what is not.

                                    B Offline
                                    B Offline
                                    Bastar Media
                                    wrote on last edited by
                                    #18

                                    Thanks a lot Mika, I found a solution. Actually the object SQLiteconnection was disposing and hence not giving the output while running from EXE, but this exception was not being catching while running from the IDE. I removed all the dispose statements in my project and not its running fine. And thanks a lot for you log file idea, it helped me a lot to detect the error.

                                    W 1 Reply Last reply
                                    0
                                    • W Wendelius

                                      As far as I can see the problem is that the connection is stored in another class, perhaps a static one. Based on this any method can dispose the connection and you would see this as a problem in the next call when the disposed connection is trying to be used. So probably the dispose happens elsewhere. To correct this you would need to do a little bit of a re-design. I've touched this problem in Properly executing database operations[^]. Have a look at the initial version and differences in version 2. I think that clarifies the situation.

                                      B Offline
                                      B Offline
                                      Bastar Media
                                      wrote on last edited by
                                      #19

                                      Hi Mika, Although I am getting the desired result, I know removing all disposed statements is not a perfect solution. Will you please help me to tell Where actually I should apply dispose statement. Regards.

                                      1 Reply Last reply
                                      0
                                      • B Bastar Media

                                        Thanks a lot Mika, I found a solution. Actually the object SQLiteconnection was disposing and hence not giving the output while running from EXE, but this exception was not being catching while running from the IDE. I removed all the dispose statements in my project and not its running fine. And thanks a lot for you log file idea, it helped me a lot to detect the error.

                                        W Offline
                                        W Offline
                                        Wendelius
                                        wrote on last edited by
                                        #20

                                        Glad to be of service :) I would recommend not using shared connection objects but having using statements instead as explained in the article. That would make the code much simple and robust in the long run :)

                                        B 2 Replies Last reply
                                        0
                                        • W Wendelius

                                          Glad to be of service :) I would recommend not using shared connection objects but having using statements instead as explained in the article. That would make the code much simple and robust in the long run :)

                                          B Offline
                                          B Offline
                                          Bastar Media
                                          wrote on last edited by
                                          #21

                                          Ok, I will keep that in mind for my future projects.

                                          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