![]() |
VOOZH | about |
The CData ADO.NET Provider for PostgreSQL enables you to rapidly develop service-oriented applications using the Windows Communication Foundation (WCF) framework, providing PostgreSQL data data to OData consumers. This article guides you through creating an entity data model for connectivity and a WCF Data Service to expose OData services. You can then consume the feed with various OData clients, such as Power Pivot or applications using the CData ADO.NET Provider for OData.
Follow the steps below to create a WCF service application that will provide connectivity to PostgreSQL data via OData.
Use the Package Manager Console in Visual Studio to install the latest version of Entity Framework. Run the following command to download and install Entity Framework automatically:
Install-Package EntityFramework
<configuration> ... <entityFramework> <providers> ... <provider invariantName="System.Data.CData.PostgreSQL" type="System.Data.CData.PostgreSQL.PostgreSQLProviderServices, System.Data.CData.PostgreSQL.Entities.EF6" /> </providers> </entityFramework> </configuration>
In the Connection properties dialog, select the CData PostgreSQL Data Source and enter the necessary credentials.
A typical connection string is below:
User=postgres;Password=admin;Database=postgres;Server=127.0.0.1;Port=5432;
To connect to PostgreSQL, set the Server, Port (the default port is 5432), and Database connection properties and set the User and Password you wish to use to authenticate to the server. If the Database property is not specified, the data provider connects to the user's default database.
You can use SSH (Secure Shell) to authenticate with PostgreSQL, whether the instance is hosted on-premises or in supported cloud environments. SSH authentication ensures that access is encrypted (as compared to direct network connections).
To connect to PostgreSQL via SSH in Password Auth mode, set the following connection properties:
To connect to PostgreSQL via SSH in Password Auth mode, set the following connection properties:
Specify the data source class and configure access to the new WCF Data Service. In the example below, the Access Rule for the entities is set to All. This means that any user will be able to read and modify data.
using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
namespace PostgreSQLService{
public class PostgreSQLDataService : DataService<PostgreSQLEntities> {
public static void InitializeService(DataServiceConfiguration config) {
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
}
}
}
You can now use the service from any OData client; for example, Excel Power Pivot.
Download a free trial of the PostgreSQL Data Provider to get started:
Download NowLearn more:
π PostgreSQL IconRapidly create and deploy powerful .NET applications that integrate with PostgreSQL-compatible database engines.