Direkt zum Hauptbereich

How to use TOracleConnection under Lazarus for Win64

Lazarus Programmers have had no possibility to use TOracleConnection under 64 Bit Windows and Lazarus for years. Even if you tried to use the TOracleConnection with a correctly configured Oracle 11g client, you were not able to connect to the Oracle Database. The error message was always:
ORA-12154: TNS:could not resolve the connect identifier specified

Today I found a simple workaround to fix this problem. It seems like the OCI.DLL from Oracle Client 11g2 is buggy. All my attempts to find identify the error ended here. I could exclude problems with the TNS systems in Oracle - or the Free Pascal file oracleconnection.pp though the error messages suggestes those problems. After investigating the function calls with Process Monitor (Procmon) I found out, that even the file TNSNAMES.ORA was found and read correctly by the Lazarus Test applictaion. So trouble with files not found or wrong Registry keys could also be eliminated. Finally I installed the Oracle Instant Client 12.1c - after a full removal of the old 11g2 Instant client. Then i changed the PATH environment variable to the new client's directory. Then i put the configured file TNSNAMES.ORA into that folder again and tested to connect to an Oracle 11g2 database server - successfully.

Now I could enable the TOracleConnection again as visual component of the Lazarus IDE and created a Lazarus Bug Report. Maybe the next version released then includes the TOracleConnection for Win64 again.

The problem

The problem is, that even with a correctly configured Oracle Client 11g the TOracleConnection in Lazarus will not work on Win64. The error message is ORA-12154.

The solution

The solution consists of three steps.

Step 1: Uninstall the Oracle Client 11g but back up your configuration files like TNSNAMES.ORA, LOGIN.SQL, GLOGIN.SQL. Then remove the old paths from the Windows Environment Variable PATH.

Step 2: Download and install the Oracle Instant Client 12.1c and Oracle SQL Plus for Win64. Install both programmes into the same folder and put the configuration files there again. No put the path of the new client location into the PATH Variable again. Test to connect to your database with SQL*Plus. If this works, you are fine.

Step 3: Enabling the TOracleConnection in your Lazarus installation again. You have to go to the "Package" menu entry. Select "Open loaded Package". In the dialog you select the package "sqldblaz". Now click "add" and go to the tab "Add files". Then browse to the file "oracleconnection.pp" under "[Lazarus directory]\fpc\2.6.2\source\packages\fcl-db\src\sqldb\oracle" and add it to the package. The next step is, to change the file "registersqldb". Search for the first occurence of
{$DEFINE HASORACLECONNECTION}
It's in an {$IFNDEF WIN64} section. You need to move it out there. I moved it under the line
{$DEFINE HASSYBASECONNECTION}
. Then save the file, compile the package via "compile" button. If it compiled successfully, click the button "use" and then "install". Now your Lazarus should be build new. After strating the IDE again, you should see the icon Icon of TOracleConnection of TOracleConnection again in the "SQLdb" tab.

Further information for using TOracleConnection

A How-to for using TOracleConnection you can find here.

Kommentare

  1. Hello Claus, thanks for your comment! But sorry, I don't understand your comment. This technical article is free to see for everyone on Blogger. You don't need an own Blogger account.

    AntwortenLöschen

Kommentar veröffentlichen

Beliebte Posts aus diesem Blog

Pi And More 11 - QMC5883 Magnetic Field Sensor Class

A little aside from the analytical topics of this blog, I also was occupied with a little ubiquitous computing project. It was about machine learning with a magnetic field sensor, the QMC5883. In the Arduino module GY-271, usually the chip HMC5883 is equipped. Unfortunately, in cheap modules from china, another chip is used: the QMC5883. And, as a matter of course, the software library used for the HMC5883 does not work with the QMC version, because the I2C adress and the usage is a little bit different. Another problem to me was, that I  didn't find any proper working source codes for that little magnetic field device, and so I had to debug a source code I found for Arduino at Github  (thanks to dthain ). Unfortunately it didn't work properly at this time, and to change it for the Raspberry Pi into Python. Below you can find the "driver" module for the GY-271 with the QMC5883 chip. Sorry for the bad documentation, but at least it will work on a Raspberry Pi 3.

Lazarus IDE and TOracleConnection - A How-To

Free programming IDEs are a great benefit for everybody who's interested in Programming and for little but ambitious companies. One of these free IDEs is the Lazarus IDE . It's a "clone" of the Delphi IDE by Embarcadero (originally by Borland). But actually Lazarus is much more than a clone: Using the Free Pascal-Compiler , it was platform-independent and cross-compiling since it was started. I am using Lazarus very often - especially for building GUIs easily because Java is still Stone-Age when a GUI is required (though there is a couple of GUI-building tools - they all are much less performant than Delphi / Lazarus). In defiance of all benefits of Lazarus there still is one Problem. Not all Components are designed for use on a 64 bit systems. Considering that 64 bit CPUs are common in ordinary PCs since at least 2008, this is very anpleasant. One of the components which will not be available on 64 bit installations is the TOracleConnection of Lazarus' SQLDB