2013年9月10日 星期二

PGNP 建置及測試

EnterpriseDB 支援 .NET 平台開發需求, 所使用 OLEDB Data Provider 之套件, 為 pgoledb.com 所提供之 Connecter driver, 該driver是需要付費的, PGNP(PostGresql Native Prodiver) 意指提供類似原生資料庫的 Data Provider. PGNP建置及測試, 在AP環境操作如下:

1. 下載 PGNP 套件
   網址為http://www.pgoledb.com/index.php?option=com_filecabinet&view=files&id=1&Itemid=68
   您可以依據您的需求下載伺服器版或桌面版套件.
   本次示範為PGNP-Postgres-SE-Trial-1.4.0.3178.exe版本

2. 安裝 PGNP, 基本上很容易, 秉持Windows安裝特性, next...n次就搞定了.
    a. 開始安裝


   b. License Agreement


   b. 接下來安裝產品及設定







   c. 產品安裝完成


3. OLEDB的第一支程式
   a. 開啟 VS2010 或 VS2012 開啟新專案
      FILE -> New Project
   b. 設定連接資料庫
      TOOLS -> Connect to Database

    c. 設定連線之Data source , 設定為 .NET Framework Data Provider for OLE DB.
 


  d. 設定OLE DB Provider 為PostgreSQL Native Provider.


  e. 設定Source or file name: 為資料庫主機,  以及設定使用者帳號及密碼和initial catalog, 並且可以透過Detail Links來設定.


  f. 將程式改寫如下,紅字的為增加部份.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.OleDb;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string connectString = null;
            OleDbConnection conn;
            OleDbDataAdapter adp = new OleDbDataAdapter();
            DataSet ds = new DataSet();
            int i = 0;
            connectString = connectString = "Provider=PGNP.1;Data Source=192.168.22.129;Persist Security Info=True;User ID=enterprisedb;Initial Catalog=edb;Extended Properties=\"PORT=5444;SSL=allow;\"";
            conn = new OleDbConnection(connectString);
            try
            {
                conn.Open();
                adp.SelectCommand = new OleDbCommand("select empno,ename from emp", conn);
                adp.Fill(ds);
                adp.Dispose();
                conn.Close();
                for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
                {
                    Console.WriteLine(ds.Tables[0].Rows[i].ItemArray[0].ToString() + "<>" + ds.Tables[0].Rows[i].ItemArray[1].ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

   g. 編譯後執行結果如下:
結論: 整體安裝過程很容易吧~ 標準MS的程序, 唯一的缺點就是"要付費", 呵呵~提供您參考.

沒有留言:

張貼留言

HDB 擴充套件 PXF (Pivotal Extension Framework) 應用

在Hadoop生態圈裡, 雖然擁有眾多生態系統工具, 但大多用戶仍然需要的是SQL的操作介面, Pivotal HDB 提供一個在Hadoop上運行的標準SQL引擎介面, 箇中好處開發者最能感受, 但本篇重點不在這, 哈哈~ 主要分享在HDB上可以輕易整合外部資料的應用. ...