* PostgreSQL Data Provider There are two ADO.NET data providers for PostgreSQL in Mono: Below, see separate Testing sections for Npgsql and Mono.Data.PostgreSqlClient. ** Current Status ** Action Plan ** Testing Mono.Data.PostgreSqlClient

Installation instructions for PostgreSQL DBMS: On Unix

On Windows

In the path mcs/class/System.Data/Test there is a test for Mono.Data.PostgreSqlClient named PostgreTest.cs. Thanks goes to Gonzalo for creating the original PostgreSQL test.

To compile the PostgresTest.cs program, do:

 mcs PostgresTest.cs \
    -r System.Data.dll \
    -r Mono.Data.PostgreSqlClient.dll

If there are compile errors, such as, can not convert IDbConnection to PgSqlConnection, then you need to run mcs like:

 mono C:/cygwin/home/MyHome/mono/install/bin/mcs.exe \
    PostgresTest.cs \
    -r System.Data.dll \
    -r Mono.Data.PostgreSqlClient.dll

To run using mint, do:

mint PostgresTest.exe

To run using mono, do:

mono PostgresTest.exe

C# Example for Mono.Data.PostgreSqlClient:

 using System;
 using System.Data;
 using Mono.Data.PostgreSqlClient;
 
 public class Test 
 {
    public static void Main(string[] args)
    {
       string connectionString = 
          "Server=localhost;" +
          "Database=test;" +
          "User ID=postgres;" +
          "Password=fun2db;";
       IDbConnection dbcon;
       dbcon = new PgConnection(connectionString);
       dbcon.Open();
       IDbCommand dbcmd = dbcon.CreateCommand();
       // requires a table to be created named employee
       // with columns firstname and lastname
       // such as,
       //        CREATE TABLE employee (
       //           firstname varchar(32),
       //           lastname varchar(32));
       string sql = 
           "SELECT firstname, lastname" + 
           "FROM employee";
       dbcmd.CommandText = sql;
       IDataReader reader = dbcmd.ExecuteReader();
       while(reader.Read()) {
            string FirstName = reader["firstname"];
            string LastName = reader["lastname"];
            Console.WriteLine("Name: " + 
                FirstName + " " + LastName);
       }
       // clean up
       reader.Close();
       reader = null;
       dbcmd.Dispose();
       dbcmd = null;
       dbcon.Close();
       dbcon = null;
    }
 }
  • Building C# Example:
  • Running the Example:
    mono TestExample.exe
    
  • ** Testing Npgsql