PostgreSQL Connection - majorsilence/My-FyiReporting GitHub Wiki

PostgreSQL Connection

Majorsilence Reporting works equally well with PostgreSQL. The "world's most advanced open source database" is a great way to experiment with professional quality databases at zero cost.

New Report wizard

In the Connection tab, PostgreSQL is an option in the drop-down list of Connection types (using a built-in copy of Npgsql so nothing extra needs to be installed). You then just need to edit the Connection string with your database name, user and password (assuming default port and localhost 127.0.0.1)
Server=127.0.0.1;Port=5432;Database=testdb;User Id=postgres;Password=postgres;

The connection details can be seen later in Data..Data Sources from the top menubar, and will appear in the RDL XML as in this example :

    <DataSources>
     <DataSource Name="DS1">
      <ConnectionProperties>
        <DataProvider>PostgreSQL</DataProvider>
        <ConnectString>Server=127.0.0.1;Port=5432;Database=testdb;Uid=postgres;Pwd=postgres;</ConnectString>
      </ConnectionProperties>
     </DataSource>
    </DataSources>
    ...
    <DataSets>
      <DataSet Name="Data">
        <Query>
          <DataSourceName>DS1</DataSourceName>
          <CommandText>SELECT test1,test2 FROM test</CommandText>
        </Query>

Notes on PostgreSQL installation

See https://www.postgresql.org and https://www.pgadmin.org.

Npgsql

Use Npgsql - an Open Source .Net Data Provider for Postgresql - to allow your .net programs to speak to Postgres, which is how Majorsilence Reporting interfaces with it (Npgsql.dll is used in the Majorsilence Reporting source code). Just "Add Reference" Npgsql.

dotnet add package Npgsql --version 9.0.3

Using Npgsql is very similar to other data access methods, using the familiar Connection and Command objects, etc -

    ' set a connection ... = new Npgsql.NpgsqlConnection("Server=127.0.0.1;Port=5432; etc    
    ' hook up a command object to that ... = new Npgsql.NpgsqlCommand("select * from table1", conn)
    ' add params if required ... command.Parameters.Add(new Npgsql.NpgsqlParameter(...
    ' Read data using DataReader ( read-only, forward-only stream of data; you must loop through it )
    '   or DataAdapters ( populate a DataSet in one go )
    ' ... NpgsqlDataReader  or  NpgsqlDataAdapter
⚠️ **GitHub.com Fallback** ⚠️