KONEKSI DATABASE IBM DB2 DENGAN C#


Sedikit tutorial buat KONEKSI DATABASE IBM DB2 DENGAN C# sekalian buat arsip.. :D

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IBM.Data.DB2;

namespace SSARPRAS.ConnectionClass
{
    class DbConnection
    {
        private static string database = "NAMA_DATABASE";
        private static string uid = "USER_ID_DB";
        private static string pwd = "PASS_DB";
        private static string ipServer = "SERVER_DB(115.178.127.123";
        private static string port = "50000";

          
        private static string strConnection;
        private static DB2Connection testCon;

       
        private static void CreateStrConnection()
        {
          strConnection = "DATABASE=" + database
                + ";SERVER=" + ipServer
                + ":" + port
                + ";UID=" + uid
                + ";PWD=" + pwd;
            testCon = new DB2Connection(strConnection);
        }

        public static DB2Connection GetConnection()
        {
            CreateStrConnection();
            return testCon;
        }

        public static string GetIpServer()
        {
            return ipServer;
        }

        public static string GetPort()
        {
            return port;
        }
    }
}

jangan lupa includkan juga component refrence IBM.DATA.DB2 pada project kalian.. simpan class tersebut dengan nama DbConnection.cs lalu untuk memnggil class koneksi tersebut pada form yg lian deklarasikan seperti berikut DB2Connection connection = ConnectionClass.DbConnection.GetConnection(); rebes dahhhh.. :D
Share on Google Plus
    Blogger Comment
    Facebook Comment

0 komentar:

Post a Comment