Дата публикации: 07.05.2017
Использование пула подключений «LCPI OLE DB Services». (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | //////////////////////////////////////////////////////////////////////////////// //Samples for LCPI ADO.NET Data provider for OLEDB. // 07.05.2017. using System; using System.Data; using System.Diagnostics; using lcpi.data.oledb; using structure_lib=lcpi.lib.structure; namespace Sample_0025{ //////////////////////////////////////////////////////////////////////////////// //class Program class Program { //OLE DB Services // - MSDASC.MSDAINITIALIZE.1 // - LCPI.OleDbServices.DataInitManager.Global.1 // - LCPI.OleDbServices.DataInitManager.Local.1 private const string c_ProgID_OleDbServices = "LCPI.OleDbServices.DataInitManager.Global.1" ; //Direct connection to Firebird DBMS private const string c_cn_str = "provider=LCPI.IBProvider.3;" + "location=localhost:d:\\database\\fb_03_0_0\\ibp_test_fb30_d3.gdb;" //any FB database + "dbclient_type=fb.direct;" + "user id=SYSDBA;" + "password=masterkey;" ; //----------------------------------------------------------------------- static int Main() { int resultCode=0; try //[catch] { using (OleDbServices services= new OleDbServices(c_ProgID_OleDbServices)) { for ( uint pass=0;pass!=3;) { ++pass; Console.WriteLine( "----------------------- pass: {0}" ,pass); for ( uint nCns=1;nCns!=4;++nCns) { Console.WriteLine( "------- nCns: {0}" ,nCns); var cns= new OleDbConnection[nCns]; try //finally { for ( uint iCn=0;iCn!=nCns;++iCn) { cns[iCn]=services.CreateConnection(c_cn_str); //throw cns[iCn].Open(); //throw Console.WriteLine( "{0}. {1}" ,iCn+1,Helper__GetCnSign(cns[iCn])); //throw } } finally { for ( uint iCn=0;iCn!=nCns;++iCn) structure_lib.DisposeUtils.Exec( ref cns[iCn]); } //finally } //for nCn } //for pass } //using services } catch (Exception exc) { resultCode=1; Console.WriteLine( "ERROR: {0} - {1}" ,exc.Source,exc.Message); } //catch return resultCode; } //main //----------------------------------------------------------------------- private static string Helper__GetCnSign(OleDbConnection cn) { string result; using ( var tr=cn.BeginTransaction()) { using ( var cmd= new OleDbCommand( null ,cn,tr)) { cmd.CommandText = "select CURRENT_CONNECTION, CURRENT_TRANSACTION from RDB$DATABASE" ; using ( var reader=cmd.ExecuteReader()) { if (!reader.Read()) throw new ApplicationException( "No record!" ); result= string .Format( "connection: {0}, transaction: {1}" , reader[0], reader[1]); } //using reader } //using cmd tr.Commit(); } //using tr return result; } //Helper__GetCnSign }; //class Program //////////////////////////////////////////////////////////////////////////////// } //nms Sample_0025 |

Output.