>> Wednesday, January 18, 2012
Last night I was trying to connect an existing Asp MVC 3 app to use an PostgreSQL database. It is using nHibernate, so I'm still going to have to determine if I need to tweak anything there, but for now just wanted to connect properly.
Install NpgSQL adapter, I used the latest .Net 4.0 install. After referencing the Npg dll in your project (plus an associated Mono dll), you can simply use their wrappers in order to connect, here you can get the gist:
var connstring = String.Format("Server=localhost;Port=5432;User Id=
var conn = new NpgsqlConnection(connstring);
const string sql = "SELECT LastName FROM Users ORDER BY LastName LIMIT 10";
var da = new NpgsqlDataAdapter(sql, conn);
var ds = new DataSet();