ASP.NET on Mono with Postgresql

Until bug 81490 was closed, Mono wasn’t capable of the ever popular “YOU DID IT WITHOUT ANY CODE” demo using Postgresql. For the unfamiliar, this is when someone demos Visual Studio’s ASP.NET designer and drags a table from the expanded database connection and drops it to the ASP.NET designer. The tool creates a connection string in the application configuration file, an SqlDataSource which uses the connection and a GridView which uses the SqlDataSource.

This code worked with Mono only if you were using SqlClient data provider. This means you were talking to Microsoft SQL Server. Most Mono users are on Linux. They want to talk to Postgresql or MySQL. Npgsql has an ADO.NET 2.0 provider model compatible library unreleased in source repository.

I’m of the opinion that declarative code such as ASP.NET or XAML or even HTML is still code. Lines of code is even moer useless a measurement here as it is in C, C++ or C#. Number of XML Nodes or number of XML Elements may be better counts of complexity in these declarative languages.

What I wanted to point out, is that it is now possible to use GridView talking to Postgresql with Mono without any code behind in C# or VB.NET.


<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”>

<html xmlns=”” >
<head runat=”server”>
<title>Npgsql with SqlDataSource Example Page</title>
<form id=”form1″ runat=”server”>

<asp:SqlDataSource ID=”SqlDataSource1″ runat=”server” ConnectionString=”<%$ ConnectionStrings:NpgsqlConnectionString %>” ProviderName=”<%$ ConnectionStrings:NpgsqlConnectionString.ProviderName %>”
SelectCommand=’select firstname,lastname,age from people’></asp:SqlDataSource>

<asp:GridView ID=”GridView1″ runat=”server” DataSourceID=”SqlDataSource1″Â >



<?xml version=”1.0″?>
<add name=”NpgsqlConnectionString” connectionString=”server=localhost;user id=test;password=test;database=test” providerName=”Npgsql” />
<add name=”Npgsql Data Provider” invariant=”Npgsql” support=”FF” description=”.Net Framework Data Provider for Postgresql Server” type=”Npgsql.NpgsqlFactory, Npgsql, Version=, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7″ />

Of course this assumes you have a Postgresql database named test with a table named people with columns firstname, lastname, age.

1 thought on “ASP.NET on Mono with Postgresql”

Comments are closed.