2

I am using Delphi 5 version and I want to connect to Oracle Database. I am having TDatabase component. I don't have any idea about how to connect to database through Delphi. Please provide the steps to connect database. thanks.

Bruce McGee
  • 15,076
  • 6
  • 55
  • 70
naren
  • 629
  • 4
  • 15
  • 22

3 Answers3

2

The TDatabase component is part of the BDE (Borland Database Engine), which is a deprecated technology, instead try using another alternatives which supports Oracle like ADO or Zeos. For an introduction to ADO check the Embarcadero Docs. Working with ADO Components and if you choose Zeos check the Official documentation.

RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • ADO components are the part of Delphi 5? – naren Jul 11 '11 at 14:36
  • Zeos is dead slow for row retrieving: it retrieve the SELECT results one row at a time!!! And there are issues for BLOB > 2KB as far as I remember. – Arnaud Bouchez Jul 11 '11 at 15:12
  • @RRUZ ADO is using OleDB to connect to Oracle. And both Oracle's and Microsoft's OleDB provider for Oracle [are buggy with BLOB fields](http://stackoverflow.com/questions/6147274/is-oraoledb-provider-in-net-unreliable-on-clob-fields/6640101#6640101): the first returns NULL for 1/4 BLOB columns, and the second just do not handle BLOB and throw an exception. So I suspect ADO is not an option for Oracle. – Arnaud Bouchez Jul 11 '11 at 15:22
  • @naren: You can use ADO with Delphi 5, without any problem. And even [directly the OleDB layer](http://blog.synopse.info/post/2011/06/27/SynOleDB%3A-OpenSource-Unit-for-direct-access-to-any-database-via-OleDB) if you wish. – Arnaud Bouchez Jul 11 '11 at 15:23
  • In Delphi 5 era, I used BDE + SQL Links with Oracle and it did work well enough. Connecting to a recent Oracle DB may be a bet, anyway, although OCI shouldn't have changed much. IIRC in D5 ADO was only in the Enterprise SKU, not in the Professional. –  Jul 11 '11 at 18:14
  • @naren, the ADO components are in the ADO palette in delphi 5. – RRUZ Jul 11 '11 at 21:35
  • @A.Bouchez, I know about the issues of the OLEDB providers for Oracle and the blob fields, but is still a valid solution, I have a couple of systems working with ADO and Oracle without any problems. About your Zeos comment , I use these component for PostgreSQL and Firebird in both cases works very well, I don't know how is the performance of ZEOS with Oracle. – RRUZ Jul 11 '11 at 21:42
  • I am unable to find the TADOCOnnection in Component Pallete. :( So anyone having idea about from where i can install these components? I am having the dbExpress Components with delphi 5 version. thanks.. – naren Jul 12 '11 at 04:40
  • @naren do you have the ADO palette in your delphi version? about dbexpress this components was introduced in Delphi 6. – RRUZ Jul 12 '11 at 05:46
  • No. I am unable to find that pallete.. :( – naren Jul 12 '11 at 06:01
  • Can someone tell me what should i mention in Tdatabase.AliasName? And what are the steps to connect to Oracle database? – naren Jul 12 '11 at 06:07
  • @RRUZ The issue with ZEOS/ZDBC is in the implementation of the Oracle Plain Driver: it retrieves one row at a time without buffering multiple rows per call... this makes the current implementation perfectly slow... :( But of course, it's only about the Oracle plain driver, not about ZEOS architecture in general, and won't affect PostgreSQL or Firebird access using this library. – Arnaud Bouchez Jul 12 '11 at 12:50
2

That's funny, I've just finished (some minutes ago) the port of my Open Source native Oracle access to Delphi 5.

Here are the main features of this unit:

  • Direct access to the Oracle Call Interface (OCI) client, with no BDE, Midas, DBExpress, nor OleDB or ODBC provider necessary;
  • Dedicated to work with any version of the Oracle OCI interface, starting from revision 8;
  • Optimized for the latest features of Oracle 11g (e.g. using native Int64 for retrieving NUMBER fields with no decimal);
  • Able to work with the Oracle Instant Client for No Setup applications;
  • Natively Unicode (uses internal UTF-8 encoding), for all version of Delphi, with special handling of each database char-set;
  • Tried to achieve best performance available from every version of the Oracle client;
  • Designed to work under any version of Windows, either in 32 or 64 bit architecture;
  • Late-binding access to column names, using a new dedicated Variant type (similar to Ole Automation runtime properties);
  • Connections are multi-thread ready with low memory and CPU resource overhead;
  • Can use connection strings like '//host[:port]/[service_name]', avoiding use of the TNSNAME.ORA file;
  • Use Rows Array and BLOB fetching, for best performance (ZEOS/ZDBC did not handle this, for instance);
  • TQuery emulation class, for direct re-use with existing code, in replacement to the BDE;
  • Handle Prepared Statements - but by default, we rely on OCI-side statement cache, if available;
  • Native export to JSON methods, which will be the main entry point for our mORMot framework;
  • Compatible with Delphi 5 up to XE;
  • Since it doesn't use the DB unit, nor DBExpress or such other technologies, works with any edition of Delphi (even Delphi XE Stater or Delphi 7 Personal);
  • Open Source, released under a MPL/GPL/LGPL license.

See this web site for more details and feedback.

You have a TQuery like wrapper, to write code just like with the BDE.

Or you can write code as such:

procedure Test(Props: TOleDBConnectionProperties; const aName: RawUTF8);
var I: ISQLDBRows;
begin
  I := Props.Execute('select * from Domain.Customers where Name=?',[aName]);
  while I.Step do
    writeln(I['Name'],' ',I.['FirstName'],' ',I['Address']);
end;

var Props: TOleDBConnectionProperties;
begin
  Props := TSQLDBOracleConnectionProperties.Create(
    'TnsName','UserName','Password',CODEPAGE_US);
  try
    Test(Props,'Smith');
  finally
    Props.Free;
  end;
end;

Unfortunately, Delphi 5 do not allow late-binding via a variant, which is allowed with Delphi 6 and up:

procedure Test(Props: TOleDBConnectionProperties; const aName: RawUTF8);
var I: ISQLDBRows;
    Customer: Variant;
begin
  I := Props.Execute('select * from Domain.Customers where Name=?',[aName],@Customer);
  while I.Step do
    writeln(Customer.Name,' ',Customer.FirstName,' ',Customer.Address);
end;

If you really want to use the DB components in a RAD approach, take a look at the corresponding page in Torry's page:

  • ATOM Access To Oracle Magic;
  • DOCI Components for Direct Oracle Access;
  • NC OCI8;
  • Orange Component Set;
  • Vlad Karpov Native Link to Oracle.

You'll find there some old free components, mostly created at Oracle 8 time (SynDBOracle is optimized for Oracle 11g but will work with earlier versions of Oracle), but which may better suit your need for Oracle connection without the BDE.

Of course, there are also some very good commercial components around, still working with Delphi 5. But you'll have to pay the high price... and should better upgrade to a newer Delphi version, by the way. ;)

Arnaud Bouchez
  • 42,305
  • 3
  • 71
  • 159
0

If you have the Enterprise version of Delphi 5 you can connecto to Oracle using the BDE and the Oracle SQL Link. That's the fastest way to use Oracle from D5. If you have the Professional version, you can use Oracle using the BDE through ODBC. The Enterprise version also should already have the ADO components, but in my tests then it was an inferior solution to the SQL Links, although if you have to port later to a newer Delphi release it is still supported while the BDE and the SQL Links are not.

The steps to connect are detailed in the help and the manuals.

  • hi i am using delphi 5 Professional version. I have BDE components.. but not getting how to connect to oracle through TDatabase. What steps i should follow? Whta shoul i mention in TDatabase properties? – naren Jul 12 '11 at 06:57
  • With Delphi 5 Pro you can connect using TDatabase only via ODBC. You have first to setup an ODBC DSN, then you can set the proper parameters in the TDatabase Params property. You can also simply link it to the BDE database alias. Again, the procedure is well detailed in the manuals and help. –  Jul 12 '11 at 07:12
  • how to setup ODBC DSN? can u plz give me small example to how to cofigure? – naren Jul 12 '11 at 07:33
  • Open "Data sources (ODBC)" in Administrative Tools and press the Help button. Also consult the Oracle ODBC driver documentation for its specific parameters. It looks you need to improve your basic knowledge about databases and their access technologies before continuing. Oracle is a very complex beast also, with a steep learning curve. I'd suggest you to spend some time documenting before attempting to setup the whole chain. –  Jul 12 '11 at 07:41
  • thanks for info.. i have not used the connection before so its getting difficult for me to understand. – naren Jul 12 '11 at 08:42
  • I have created the ODBC DSN. can u plz tell me how to map it to TDatabase.. thanks for help. – naren Jul 12 '11 at 08:43
  • I'd suggest you to read the "Developing Database Applications" topic in the Delphi 5 help (or the manual). It will give you the needed overview on how to use TDatabase, TSession and other needed components to correctly setup a database application. You need to understand the VCL database architecture, simply telling you "set this property to X, that other to Y" won't help much. Anyway, if BDE is configured correctly, you should now see the ODBC DNS in the AliasName property list. –  Jul 12 '11 at 08:52
  • thanks. I will go through help. ODBC DNS created correctly but its not showing in alias name list. what is the reason do u have any idea? – naren Jul 12 '11 at 08:57
  • @ldsandon let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/1352/discussion-between-naren-and-ldsandon) – naren Jul 12 '11 at 09:09
  • I can see that ODBC connection in BDE Administartor. – naren Jul 12 '11 at 09:21