* PostgreSQL and Mono When it comes to Mono and PostgreSQL, there are many ways you can handle your data. You have many Mono Data Providers which can be used to access data from a application written for Mono. Then there is the future goal of having the ability to host Mono within PostgreSQL to have the applications run on the server which makes things much faster. * Hosting Mono in PostgreSQL There is a project to host Mono within PostgreSQL. plMono is a PostgreSQL language using the embedded Mono runtime. It provides support for writing functions in C#, or any other language that supports .NET. * Data Providers There are many ADO.NET data providers for PostgreSQL: There are two providers created specifically for PostgreSQL included with 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 = (string) reader["firstname"];
            string LastName = (string) 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