PostgreSql ConnectionString error: Keyword not supported: 'host'.

2 Answers 5 Views
DataSource SQL
Andrea
Top achievements
Rank 1
Iron
Andrea asked on 23 Jun 2025, 08:55 AM
Hello,

I created a report using the Standalone Designer (in .trdp format). In the data connection, I configured it to use a shared connection. From within the Designer, everything works fine — I can preview and export to PDF without any issues.

I then created a console project (code shown below) to try exporting the report to PDF.

In the project's configuration file, I added a connection string to use.

However, when executing the following line:


RenderingResult result = reportProcessor.RenderReport("PDF", sourceReportSource, deviceInfo);

I get an error in the Inner Exception:
Keyword not supported: 'host'.

My PostgreSQL connection string is:
"Host=localhost;Port=5432;Database=crp;Username=postgres;Password=****"

But the connection string is correct — it’s exactly the same one I use in the Standalone Designer, where it works without any problem.

If I embed the connection string directly in the report instead of using a shared connection, everything works fine.

Any idea what could be causing this?



        static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);

            IConfiguration config = builder.Build();

            string connectionString = config.GetConnectionString("crp");

            string reportName = @"D:\dev\telerik-reporting\reports\report.trdp";

            var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();

            // set any deviceInfo settings if necessary
            var deviceInfo = new System.Collections.Hashtable();
            var sourceReportSource = new Telerik.Reporting.UriReportSource();
            sourceReportSource.Uri = reportName;
          
            sourceReportSource.Parameters.Add("procedure_id", 6);

            RenderingResult result = reportProcessor.RenderReport("PDF", sourceReportSource, deviceInfo);

            if (!result.HasErrors)
            {
                //string fileName = result.DocumentName + "." + result.Extension;
                string fileName = "file.pdf";
                string path = @"D:\";
                //string path = System.IO.Path.GetTempPath();
                string filePath = System.IO.Path.Combine(path, fileName);

                using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
                {
                    fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
                }
            }

        }


2 Answers, 1 is accepted

Sort by
0
Accepted
Andrea
Top achievements
Rank 1
Iron
answered on 24 Jun 2025, 02:34 PM

Hello Dimitar,

thank you very much now works perfectly.

I had already installed the Npgsql nuget package but I missed the ConnectionString note on this page

If I use this configuration in the appsettings.json it doesn't works:

{
  "ConnectionStrings": {
    "crp": "Host=localhost;Port=5432;Database=crp;Username=postgres;Password=******"
    }
}

Instead if I use the previous .net format works:
{
  "ConnectionStrings": {
    "crp": {
      "connectionString": "Host=localhost;Port=5432;Database=crp;Username=postgres;Password=******",
      "providerName": "Npgsql"
    }
  }
}

Thank you!

Regards
0
Dimitar
Telerik team
answered on 24 Jun 2025, 01:15 PM

Hello Andrea,

Thank you for the shared code and the additional information!

Since you have a PostgreSQL database and connection string, I assume that you are using the Npgsql data provider in the Standalone Report Designer, is that correct?

The likely reason for the same connection string working with the Standalone Report Designer is that the Npgsql provider is installed globally on the computer, thus our application is able to load it and create a connection with the given connection string.

On the other hand, when the reports are rendered in another application, you would need to ensure that the data provider is installed there so that it can be used by our engine. The error about the "host" keyword suggests that the Npgsql data provider is not available in the application where you render the reports, thus the engine must be falling to the default data provider - System.Data.SqlClient, which does not seem to recognize the "host" keyword, and thus the error is thrown.

To resolve the issue, please ensure that the Npgsql data provider and its dependencies are installed in your project, and also specify a correct "providerName" setting for the connection string so that it uses the Npgsql provider.

Please have a look at the Setting up the Npgsql Data Provider in .NET Applications section of the Integrating the Npgsql Data Provider - Telerik Reporting article for more details on how to do that.

I hope that the provided information and suggestions will help. In case you need further assistance, please send me a copy of your project so that I can inspect it locally and verify that the Npgsql provider is installed on it.

Regards,
Dimitar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
DataSource SQL
Asked by
Andrea
Top achievements
Rank 1
Iron
Answers by
Andrea
Top achievements
Rank 1
Iron
Dimitar
Telerik team
Share this question
or