Telerik.Reporting.Processing.Data.SqlDataSourceException in .net core api

5 posts, 0 answers
  1. Sameer
    Sameer avatar
    9 posts
    Member since:
    Jul 2019

    Posted 05 Aug Link to this post

     

    following exception occured in .net core api:

    Telerik.Reporting.Processing.Data.SqlDataSourceException: Unable to establish a connection to the database. Please verify that your connection string is valid. In case you use a named connection string from the application configuration file, make sure the name is correct and the connection string settings are present in the configuration file of your application. ---> System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.

       at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue)
       at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms, Boolean firstKey)
       at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms)
       at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
       at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)
       at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)
       at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)
       at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
       at Telerik.Reporting.Processing.Data.SqlCommandProvider.CreateConnection(String connectionString)
       at Telerik.Reporting.Processing.Data.SqlQueryProvider.CreateConnection()

  2. Sameer
    Sameer avatar
    9 posts
    Member since:
    Jul 2019

    Posted 05 Aug in reply to Sameer Link to this post

    able to sort out this issue
    but following generates blank pdf in c# .net core api

    public IActionResult ExportToPDF()

    {
     reportToExport.Name = "dummyreport";

                ReportProcessor reportProcessor = new ReportProcessor();
                Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
                instanceReportSource.ReportDocument = reportToExport;
                instanceReportSource.Parameters.Add("Id", "123");
                instanceReportSource.Parameters.Add("name", "test report");


                RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);

                string fileName = result.DocumentName + ".pdf";
                          
                using (FileStream fs = new FileStream(this.reportsPath + "vendorResponse.pdf", FileMode.Create))
                {
                    fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
                    fs.Close(); // obsolete, I think)
                    fs.Dispose(); // obsolete, I think)
                }

                return File(result.DocumentBytes, "application/pdf", fileName);

    }

  3. Neli
    Admin
    Neli avatar
    100 posts

    Posted 08 Aug Link to this post

    Hi Sameer,

    It seems that the report object is not assigned correctly to the InstanceReportSource instance. For an example of using InstanceReportSource, you can refer to Example section of the article. Note that we recommend the usage of uriReportSource (if the report was created through the Standalone Report designer) and typeReportSource (if the report was created through the Visual Studio Report designer). The reason is that they provide better performance and compatibility. By these two options you only create a reference to the report. 
    The instanceReportSource is a legacy report source option. By using it, you create a new instance of the report which makes this option more complex and more difficult to maintain.

    Regards,
    Neli
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  4. Sameer
    Sameer avatar
    9 posts
    Member since:
    Jul 2019

    Posted 09 Aug in reply to Neli Link to this post

    exception caused while generating Telerik report

    Cause is that parameters passed from c# code did not get bind with Telerik report data source at runtime.

    i pass value to report(designed using standalone report designer) as below. The report contain sqldatasource which will take value passed value as input and get data from DB.

     

      ReportProcessor reportProcessor = new ReportProcessor();
                Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
                instanceReportSource.ReportDocument = reportToExport;
                instanceReportSource.Parameters.Add("Id", "123");
                instanceReportSource.Parameters.Add("name", "test report");

                RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);

                string fileName = result.DocumentName + ".pdf";

  5. Silviya
    Admin
    Silviya avatar
    380 posts

    Posted 14 Aug Link to this post

    Hi Sameer,

    If you're trying to dynamically pass a parameter to the SqlDataSource, the approach is to use a report parameter.

    When the SQL query has parameters you can set their value on step 4 of SqlDataSource Wizard. On this step, you can map the values of the data source parameters (for example @Id and @Name) to a report parameter (newly created 'Id' and 'Name' report parameters) - Using Parameters with Data Source objects. This way you can use the standard report parameter user interface to provide values for your data source parameters.

    Updating report parameters from the calling application can be achieved with ReportSource.Parameters collection which is mapped to Report.ReportParameters, for example

    ReportProcessor reportProcessor = new ReportProcessor();
    Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
    instanceReportSource.ReportDocument = new MyTestReport();;
    instanceReportSource.Parameters.Add(new Telerik.Reporting.Parameter("Id", "123"));
    instanceReportSource.Parameters.Add(new Telerik.Reporting.Parameter("name", "test report"));
    
    RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);
    
    string fileName = result.DocumentName + ".pdf";

    Best Regards, Silviya
    Progress Telerik

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top