ReportGeneration Application

I have to create a web app. that prints out the statistics for student applicants in a .txt file. The data in form of Tables resides in a SQL server. Now, the user provides a date range(for eg. from 12/1/2006 to 1/1/2007) and the outputted text file will have the following:

- The Number of applications received

- The number of applications approved

- Number of students with a criminal background and the type of background

- Number of applicants who applied last year.

I was wondering that from a design standpoint, what would be an elegant and effecient way to extract the data from the server, store it in some kind of data structure and output the contents in a text file. I was looking at Enterprise library and interfaces but wasn't sure if that's a good way to work on a project like this one. Any advise will be appreciated.

Thanks



Answer this question

ReportGeneration Application

  • osamaT

    When i worked on website using .NET 1.1, i used grid export feature to export grid data to excel. Try to search web for such solution.

  • Vaassu

    This is not very usefule. 'The problem is to do with security and web pages'. We already know that from the original error message which you are just rephrasing. Numerous people seem to have this problem so I would think Microsoft could come up with a better solution than 'try something and see'. In my case, yes the code works from a windows app, it was copied from one. The interop.excel.dll has permissions set to full for IIS account, IUSR account .NET account, me and the everyone group. What else do we need to check permissions on, and who else do we need to give permissions to would be a good answer.

  • PeteDev1

    This is not an area where I have much experience, but I think the problem has to do with the fact that you are in a web app, and hence in a sandbox of sorts. Try running the same code from a Win Forms or Console Application, and if it works, then you know the problem has to do with security and web apps. You might to sign your web app before you can use it to access system resources.

    - Charlie



  • Syed Mazhar Hasan

    In most cases, you should not need an intermediate data structure for a problem of this kind. You should be able to compose a single SQL statement that will return your data in sequential rows that you can access easily with basic classes like SqlDataReader and SqlCommand. It is just a question of finding the right SQL statement, then use cookie cutter code to iterate over the data.

    Here is sample code from the Visual Studio help file:

    private static void ReadOrderData(string connectionString)
    {
      string queryString =
        "SELECT OrderID, CustomerID FROM dbo.Orders;";
    
      using (SqlConnection connection =
            new SqlConnection(connectionString))
      {
        SqlCommand command =
          new SqlCommand(queryString, connection);
        connection.Open();
    
        SqlDataReader reader = command.ExecuteReader();
    
        // Call Read before accessing data.
        while (reader.Read())
        {
          Console.WriteLine(String.Format("{0}, {1}",
            reader[0], reader[1]));
        }
    
        // Call Close when done reading.
        reader.Close();
      }
    }
    

    - Charlie



  • Jonas.S

    Thanks a lot..but here's the thing, when I declare something like this:

    Excel.Application oXL = new Excel.Application();

    I get an exception as follows:

    Description: An unhandled exception occurred during the execution of

    the current web request. Please review the stack trace for more

    information about the error and where it originated in the code.

    Exception Details: System.UnauthorizedAccessException: Access is

    denied.

    ASP.NET is not authorized to access the requested resource. Consider

    granting access rights to the resource to the ASP.NET request identity.

    ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5

    or Network Service on IIS 6) that is used if the application is not

    impersonating. If the application is impersonating via <identity

    impersonate="true"/>, the identity will be the anonymous user (typically

    IUSR_MACHINENAME) or the authenticated request user.

    To grant ASP.NET write access to a file, right-click the file in

    Explorer, choose "Properties" and select the Security tab. Click "Add"

    to add the appropriate user or group. Highlight the ASP.NET account, and

    check the boxes for the desired access.

    Source Error:

    Line 155: //Open the HTML file in Excel.

    Line 156:

    Line 157: Excel.Application oExcel = new Excel.Application();

    Line 158: oExcel.Visible=true;

    Line 159: oExcel.UserControl=true;

    Line 157 is where it is getting stuck. Can somebody point out what the problem might be


  • Ori&amp;#39;

    Thanks for the response. I was thinking about using microsoft reporting service because eventually all the data from the text file needs to be transported to an excel spreadsheet. Has anyone integrated their C#.NET Web application with Microsoft reporting services to generate excel spreadsheets of the data
  • JAXN

    Thanks for the response. Are you talking about datagrid data here What I am trying to do here is export data(data extracted from the sql server) in a format specified by an excel template. I am not sure whether I should use datagrids here..I am using datasets and datatables and then using the data in the datatable to populate the spreadsheet cell by cell. This is all being done in a separate class which deals exclusively with populating the spreadsheet.

    I am just trying to figure out why should the application throw an exception when I do something as follows:

    Excel.Application xcl = new Excel.Application();

    Thanks


  • fjcardoso

  • Matthijs Koopman

    I guess I will just write all the data in an XML file and then open it up using excel 2003. Opening up an instance of excel on the server is creating all sorts of issues which i don't think I should go into at this point. Does anybody know anything about stylesheets that can take the XML data and display it in a desired format in excel
  • ReportGeneration Application