This is a migrated thread and some comments may be shown as answers.

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

4 Answers 484 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sameer
Top achievements
Rank 1
Sameer asked on 05 Aug 2019, 12:14 PM

 

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()

4 Answers, 1 is accepted

Sort by
0
Sameer
Top achievements
Rank 1
answered on 05 Aug 2019, 12:45 PM

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);

}

0
Neli
Telerik team
answered on 08 Aug 2019, 11:28 AM
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
0
Sameer
Top achievements
Rank 1
answered on 09 Aug 2019, 05:10 PM

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";

0
Silviya
Telerik team
answered on 14 Aug 2019, 06:52 AM

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
Tags
General Discussions
Asked by
Sameer
Top achievements
Rank 1
Answers by
Sameer
Top achievements
Rank 1
Neli
Telerik team
Silviya
Telerik team
Share this question
or