Publish date: 2015-03-26

Collaboration of ADO.NET, ADODB and OLE DB technologies. (C#)

////////////////////////////////////////////////////////////////////////////////
//Samples for LCPI ADO.NET Data provider for OLEDB.
//                                                                   26.03.2015.
using System;
using System.Data;
using System.Diagnostics;
using lcpi.data.oledb;

using com_lib=lcpi.lib.com;
using adodb_lib=lcpi.lib.adodb;

namespace Sample_0021{
////////////////////////////////////////////////////////////////////////////////
//
// LCPI.IBP.Samples.IBGenManager.1
//  - Sample COM-object (writed on C++) from IBProvider installation kit.
//    Works with OLEDB provider through native OLEDB interfaces.
//
////////////////////////////////////////////////////////////////////////////////
//
// Scenario:
// - ADO.NET provider creates the connection to database
// - ADODB connection initiates the transaction
// - Sample COM object (GenManager) executes "GEN_ID" statement for generation of record identifier
// - ADODB connection commits the transaction
//
////////////////////////////////////////////////////////////////////////////////
//class Program

class Program
{
 private const string c_cn_str
   ="provider=LCPI.IBProvider.3;"
   +"location=localhost:d:\\database\\employee.fdb;"
   +"user id=gamer;"
   +"password=vermut;";

 //-----------------------------------------------------------------------
 static int Main()
 {
  int resultCode=0;

  try //[catch]
  {
   using(var oledbCn=new OleDbConnection(c_cn_str))
   {
    Console.WriteLine("[ADO.NET] Connection to database...");

    oledbCn.Open();

    //--------------------------------------
    Console.WriteLine("Creation of ADODB.Connection object ...");

    dynamic adodbCn=com_lib.object_utils.CreateInstance
                     ("ADODB.Connection",
                      com_lib.ClsCtxCode.CLSCTX_INPROC_SERVER).GetObject();

    Console.WriteLine("Connect ADODB to ADO.NET");

    adodb_lib.AdoDbConstructor.attach_adodb_cn_to_oledb_session
     (adodbCn,
      oledbCn.GetNativeSession());

    //--------------------------------------
    Console.WriteLine("[ADODB] Start transaction...");

    adodbCn.BeginTrans();

    //--------------------------------------
    Console.WriteLine("Creation of LCPI.IBP.Samples.IBGenManager.1");

    dynamic genMng=com_lib.object_utils.CreateInstance
                     ("LCPI.IBP.Samples.IBGenManager.1",
                      com_lib.ClsCtxCode.CLSCTX_INPROC_SERVER).GetObject();

    //--------------------------------------
    Console.WriteLine("Connect GenMng to ADODB");

    genMng.Connection=adodbCn;

    //--------------------------------------
    Console.WriteLine("[GenMng] Generate ID: {0}",
                      genMng.GenID("CUST_NO_GEN"));

    //--------------------------------------
    Console.WriteLine("[ADODB] Commit transaction...");

    adodbCn.CommitTrans();
   }//using oledbCn
  }
  catch(Exception exc)
  {
   resultCode=1;

   Console.WriteLine("ERROR: {0} - {1}",exc.Source,exc.Message);
  }//catch

  return resultCode;
 }//Main
};//class Program

////////////////////////////////////////////////////////////////////////////////
}//nms Sample_0021



Output of sample.
Output.