.NET Core 'Can't find object MsSqlDataConnection'

I am working to implement a Fast Report for in a .NET Core application.

The report uses MS SQL Connection with a query and passes the connection string as a parameter.

This same .FRX file is currently working in .NET Framework web application. In .NET Core application, at Report.Load(), an error gets thrown 'An exception of type 'FastReport.Utils.ClassException' occurred in FastReport.dll but was not handled in user code. Can't find object MsSqlDataConnection'

Any ideas on what is the cause of this error? Are reports with MS SQL Connection supported in Fast Reports .NET Core at all? Having trouble finding resources to implement this.
public IActionResult CIPVIT()
        {
            var dateParameter = DateTime.Now;

            var Report = new WebReport();

            Report.Report.Load($@"ReportFiles/ReportName.frx"); //error thrown here.
            Report.Report.SetParameterValue("ConnectionStringParameter", "Data Source=my connection string info here");
            Report.Report.SetParameterValue("CutOffDate", dateParameter);

            ViewBag.WebReport = Report;
            return View();
        }

Comments

  • edited 5:46AM
    1. in startup.cs
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    
    namespace WebReportCore
    {
        public class Startup
        {
            public Startup(IConfiguration configuration)
            {
                Configuration = configuration;
            }
    
            public IConfiguration Configuration { get; }
    
            public void ConfigureServices(IServiceCollection services)
            {
                services.AddMvc();
                services.AddHttpClient();
            }
    
            public void Configure(IApplicationBuilder app, IHostingEnvironment env)
            {
                FastReport.Utils.RegisteredObjects.AddConnection(typeof(MsSqlDataConnection));
                app.UseFastReport();
                app.UseStaticFiles();
                app.UseMvc(routes =>
                {
                    routes.MapRoute(
                        name: "default",
                        template: "{controller=Home}/{action=Index}/{id?}");
                });
            }
        }
    
        public class MsSqlDataConnection : FastReport.Data.DataConnectionBase
        {
            public override string QuoteIdentifier(string value, System.Data.Common.DbConnection connection)
            {
                return "\"" + value + "\"";
            }
    
            public override System.Type GetConnectionType()
            {
                return typeof(System.Data.SqlClient.SqlConnection);
            }
    
            public override System.Type GetParameterType()
            {
                return typeof(System.Data.SqlDbType);
            }
    
            public override System.Data.Common.DbDataAdapter GetAdapter(string selectCommand, System.Data.Common.DbConnection connection, FastReport.Data.CommandParameterCollection parameters)
            {
                System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter(selectCommand, connection as System.Data.SqlClient.SqlConnection);
                foreach (FastReport.Data.CommandParameter p in parameters)
                {
                    System.Data.SqlClient.SqlParameter parameter = adapter.SelectCommand.Parameters.Add(p.Name, (System.Data.SqlDbType)p.DataType, p.Size);
                    parameter.Value = p.Value;
                }
                return adapter;
            }
        }
    }
    

    2. in MVC Controller
    FastReport.Web.WebReport wr = new FastReport.Web.WebReport();
    wr.Report.Load(@"d:\untitled.frx");
    wr.Report.Dictionary.Connections[0].ConnectionString = @"Data Source=(local)\SQLEXPRESS;AttachDbFilename=;Initial Catalog=mydatabase;Integrated Security=False;Persist Security Info=True;User ID=sa;Password=user";
    ViewBag.WebReport = wr;
    return View();
    

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.