Listing Establishing a Connection with Bdp Connection

1: const

2: cnStr = ' assembly=Borland.Data.Interbase, Version=1.5.0.0, '+ 3: 'Culture=neutral,PublicKeyToken=91d62ebb5b0d1b1b;

┬╗vendorclient=gds32.dll;'+

4: ' database=C:\Program Files\Common Files\Borland

┬╗Shared\Data\EMPLOYEE.GDB;'+

5: 'provider=Interbase;username=sysdba;password=masterkey';

6: procedure TWinForm.btnOpen_Click(sender: System.Object; 7: e: System.EventArgs); 8: var

9: bdpCn: BdpConnection; 10: begin

11: bdpCn := BdpConnection.Create(cnStr);

12: Include(bdpCn.StateChange, Self.BdpCn_StateChange);

13: bdpCn.Open;

14: bdpCn.Close;

. Find the code on the CD: \Code\Chapter 24\Ex0i.

Lines 2-5 represent the connection string to an Interbase database. The ConnectionString assignment is handled implicitly by the BdpConnection.Create() constructor call (line 11). Line 12 creates and also demonstrates adding an event handler to the stateChange event. Both the assignment to ConnectionString and to the stateChange event could have been done at design time through the Object Inspector. The last section of this chapter demonstrates using the Connections Editor to create a connection for the BdpConnection at design time.

When using the BdpConnection, you must always match a call to Open() with a call to ciose() as this is not done implicitly. The bdpCn_stateChange() event handler performs one line of code:

ListBoxl.Items.Add(e.CurrentState)

This code writes out one of the two states in which the BdpConnection can be. This is either Open or Ciosed.

General use of the BdpConnection class is similar to the SqiConnection class discussed in previous chapters.

0 0

Post a comment