Connecting SQL Server Data to RDLC reports in Blazor .Net Framework

Geoffrey de Sousa 0 Reputation points
2024-05-13T09:36:27.6966667+00:00

Hello,

I am trying to create/integrate RDLC reports in Blazor .NET framework.

So far: I have managed to open a RDLC report thanks this Question and Answer: https://learn.microsoft.com/en-us/answers/questions/1467901/integrating-rdlc-reports-in-blazor-web-apps
I am unable to pull the data set from an SQL Server Database. I hit an error: AspNetCore.Reporting.LocalProcessingException: 'An error occurred during local report processing.;An error has occurred during report processing. Query execution failed for dataset 'DataSet1'. Format of the initialization string does not conform to specification starting at index 0.' ProcessingAbortedException: An error has occurred during report processing. Query execution failed for dataset 'DataSet1'. Format of the initialization string does not conform to specification starting at index 0.

I believe the connection string is correct because when I choose the dataset I can see all the relevant tables/fields appear. Is there something I am am missing ?

Ideally I would like to handle the connection string and query in the code similar to this example: https://learn.microsoft.com/en-us/sql/reporting-services/application-integration/using-the-webforms-reportviewer-control?view=sql-server-ver16

However I cant find any documentation on how to handle connection string or query in Blazor .NET framework with the RDLC.

Could someone please share examples and resources for Connecting SQL Server Data into RDLC reports with .NET Blazor framework? Thank you.

Kind Regards, Geoffrey.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,459 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,240 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,420 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,896 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Geoffrey de Sousa 0 Reputation points
    2024-05-22T08:23:01.3666667+00:00

    public async Task<DataTable> PopulateDataTable()

    {

    DataTable dataTable = new DataTable();
    
    using (var conn = new SqlConnection(_configuration.Value))
    
    {
    
        string query = @"<--SQL QUERY HERE-->";
    
        conn.Open();
    
        try
    
        {
    
            var model = await conn.QueryAsync<Model>(query,  commandType: CommandType.Text);
    
            if (!model.Any())
    
            {
    
                throw new Exception("No data found.");
    
            }
    
            // Create columns for the DataTable
    
            foreach (var property in typeof(Model).GetProperties())
    
            {
    
                dataTable.Columns.Add(property.Name, Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType);
    
            }
    
            // Populate DataTable with data
    
            foreach (var item in model)
    
            {
    
                var row = dataTable.NewRow();
    
                foreach (var property in typeof(Model).GetProperties())
    
                {
    
                    var value = property.GetValue(item) ?? DBNull.Value;
    
                    row[property.Name] = value;
    
                }
    
                dataTable.Rows.Add(row);
    
            }
    
        }
    
        catch (Exception ex)
    
        {
    
            throw ex; // Consider logging the exception
    
        }
    
        finally
    
        {
    
            conn.Close();
    
        }
    
    }
    
    return dataTable;
    

    }