필자가 가진 Visual Studio 2010 을 이용해서 앞서 PHP 와 PERL 로 짠 초간단 프로그램을 .NET 으로도 코딩해보겠습니다.
WEB 이 아닌 콘솔프로그램입니다.
소스는 다음과 같습니다.
/*
* Copyright( c) PostgresDBA.com
*/
using System;
using Npgsql; // Npgsql .NET Data Provider for PostgreSQL
namespace PostgreSQL_sample
static void Main(string[] args)
// Specify connection options and open an connection
NpgsqlConnection conn = new NpgsqlConnection("Server=10.10.10.94;User Id=scott;Password=tiger;Database=scottdb;");
NpgsqlCommand cmd = new NpgsqlCommand("select ename, empno from emp", conn);
NpgsqlDataReader dr = cmd.ExecuteReader();
// Read all rows and output the first column in each row
Console.Write("{0}=>{1}\n", dr[0], dr[1]);
닷넷으로 PostgreSQL 과 연동하기 위해서는 아래 두개 어셈블리를 References 에 추가해야 합니다.
Mono.Security.dll
Npgsql.dll
PostgreSQL .NET Data Provider 는 아래 싸이트에서 다운로드 하시면 됩니다.
http://npgsql.projects.pgfoundry.org/
아래 이미지 우측 상단의 빨간 박스를 주목하세요.