i get this error with ssrs reports using sqLite , entity frame work and .net6

Amr Yakout 40 Reputation points
2023-09-11T19:05:46.6133333+00:00

i get this error with ssrs reports using SQLiteScreenshot 2023-09-11 215904

, entity frame work and .net6

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
694 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,323 questions
SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,784 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,168 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,116 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 54,621 Reputation points
    2023-09-12T18:47:27.5866667+00:00

    IQueryable queries are executed when iterated. You are disposing the context before the query is run, thus the dispose context error. also there is no reason to call dispose in using block. try:

    using (DataContext context = new DataContext())
    {
          var dayRegime = context?.DayRegimes.Where(x => x.DayId == _dayRegime.DayId);
    
          ReportRegime1.LocalReport.DataSources.Add(new ReportDataSource
          {
             Name = "DataSet2",
             Value = dayRegime
          });
    
          ReportRegime1.SetDisplayMode(DisplayMode.PrintLayout);
          ReportRegime1.LocalReport.EnableExternalImages = true;
          ReportRegime1.Refresh();
          ReportRegime1.RefreshReport();
    }
    

    if the report will re-query internally, you can still get the error. then just run query first:

    using (DataContext context = new DataContext())
    {
          var dayRegime = context?.DayRegimes.Where(x => x.DayId == _dayRegime.DayId).ToList();
    
          ReportRegime1.LocalReport.DataSources.Add(new ReportDataSource
          {
             Name = "DataSet2",
             Value = dayRegime.ToList()  // run query before passing
          });
    
          ReportRegime1.SetDisplayMode(DisplayMode.PrintLayout);
          ReportRegime1.LocalReport.EnableExternalImages = true;
          ReportRegime1.Refresh();
          ReportRegime1.RefreshReport();
    }
    
    1 person found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 54,621 Reputation points
    2023-09-11T20:49:21.7+00:00

    as SQLite is a process hosted database, it only supports one active db context per database file. you appear to not managing your db context correctly, reusing a disposed context.

    0 comments No comments

  2. Amr Yakout 40 Reputation points
    2023-09-12T18:22:35.8233333+00:00

    this my code in the Window_Loaded

            }
            private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                ReportRegime1.LocalReport.ReportEmbeddedResource = "DinaDiet.Reports.ReportRegime.rdlc";
                ReportRegime1.LocalReport.DataSources.Clear();
    
                using (DataContext context = new DataContext())
                {
    
                    ReportRegime1.LocalReport.DataSources.Add(new ReportDataSource
                    {
                        Name = "DataSet2",
                        Value = context?.DayRegimes.Where(x => x.DayId == _dayRegime.DayId)
                    });
                }
    
                ReportRegime1.SetDisplayMode(DisplayMode.PrintLayout);
                ReportRegime1.LocalReport.EnableExternalImages = true;
                ReportRegime1.Refresh();
                ReportRegime1.RefreshReport();
            }
    
    
            
               
               ```
    
    
    0 comments No comments

  3. Amr Yakout 40 Reputation points
    2023-09-12T18:27:06.8633333+00:00

    this my ssrs and DataSets

    d

    0 comments No comments