PI SQL Client ODBC Administrator Guide
PI SQL Client ODBC Administrator Guide
PI SQL Client ODBC Administrator Guide
2021
© 2015-2023 by AVEVA Group plc or its subsidiaries. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means,
mechanical, photocopying, recording, or otherwise, without the prior written permission of AVEVA Group plc. No liability
is assumed with respect to the use of the information contained herein.
Although precaution has been taken in the preparation of this documentation, AVEVA assumes no responsibility for
errors or omissions. The information in this documentation is subject to change without notice and does not represent a
commitment on the part of AVEVA. The software described in this documentation is furnished under a license
agreement. This software may be used or copied only in accordance with the terms of such license agreement.
AVEVA, the AVEVA logo and logotype, OSIsoft, the OSIsoft logo and logotype, ArchestrA, Avantis, Citect, DYNSIM, eDNA,
EYESIM, InBatch, InduSoft, InStep, IntelaTrac, InTouch, Managed PI, OASyS, OSIsoft Advanced Services, OSIsoft Cloud
Services, OSIsoft Connected Services, OSIsoft EDS, PIPEPHASE, PI ACE, PI Advanced Computing Engine, PI AF SDK, PI API,
PI Asset Framework, PI Audit Viewer, PI Builder, PI Cloud Connect, PI Connectors, PI Data Archive, PI DataLink, PI DataLink
Server, PI Developers Club, PI Integrator for Business Analytics, PI Interfaces, PI JDBC Driver, PI Manual Logger, PI
Notifications, PI ODBC Driver, PI OLEDB Enterprise, PI OLEDB Provider, PI OPC DA Server, PI OPC HDA Server, PI
ProcessBook, PI SDK, PI Server, PI Square, PI System, PI System Access, PI Vision, PI Visualization Suite, PI Web API, PI
WebParts, PI Web Services, PRiSM, PRO/II, PROVISION, ROMeo, RLINK, RtReports, SIM4ME, SimCentral, SimSci, Skelta,
SmartGlance, Spiral Software, WindowMaker, WindowViewer, and Wonderware are trademarks of AVEVA and/or its
subsidiaries. All other brands may be trademarks of their respective owners.
U.S. GOVERNMENT RIGHTS
Use, duplication or disclosure by the U.S. Government is subject to restrictions set forth in the license agreement with
AVEVA Group plc or its subsidiaries and as provided in DFARS 227.7202, DFARS 252.227-7013, FAR 12-212, FAR
52.227-19, or their successors, as applicable.
PI SQL Client ODBC
Contents
Contents
PI SQL Client ODBC. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 3
PI SQL Client ODBC
Contents
Configure Oracle. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Create a driver Init file (init<sid>.ora). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Configure Oracle Net Listener for the gateway (listener.ora). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Configure the Oracle database for gateway access (tnsnames.ora). . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Stop and start the Oracle Net Listener for the gateway. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Connection to the gateway. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Create database links. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Enable TO_NCHAR capability. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Installation and configuration checklist. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Query optimization and post-processing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Unicode data handling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Workarounds for TO_NCHAR capability. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Workaround 1 - use an explicit cast. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Workaround 2 - use pass-through query. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Workaround 3 - change Unicode columns into ASCII. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Variant columns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Comparison with numeric values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Comparison with string literals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Workarounds for comparisons with string literals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Workaround 1 - use native Unicode column. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Workaround 2 - change Unicode columns into ASCII. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Recommendation for variant columns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Oracle specific issues. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Timestamp conditions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Workaround - specify very small subsecond part. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Oracle resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Logging options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 4
PI SQL Client ODBC
PI SQL Client ODBC
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 5
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
• SQL-based data access (PI OLEDB Provider, PI OLEDB Enterprise, PI JDBC Driver, PI ODBC Driver, PI SQL Client
OLE DB, PI SQL Client ODBC, and PI SQL Client JDBC)
• Service-oriented architecture (PI Web API)
• Programmatic access (AF SDK)
Developer Technologies products are available for download from the OSIsoft Customer Portal Products page at
no charge. You can develop applications using the Developer Technologies tools and your PI Server. If you do not
have access to a PI Server, you can obtain development licenses for the PI Server through membership in the PI
Developers Club. For details, see PI Developers Club FAQ.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 6
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
Architecture
PI SQL Client ODBC is an implementation of the ODBC standard based on the ODBC API.
Communication from PI SQL Client ODBC to the PI System requires PI SQL Data Access Server (RTQP Engine)
installed and running on the AF Server. It provides secure network communication through Net.Tcp or HTTPS to
PI SQL Client ODBC.
Note: For HTTPS connections, PI SQL Client ODBC supports Transport Layer Security (TLS), versions 1.0, 1.1, and
1.2. The TLS version is negotiated with PI SQL DAS and depends on its version and the operating systems
involved.
PI SQL Data Access Server (RTQP Engine) runs on Windows and PI SQL Client ODBC is supported on Windows
operating systems.
Deployment
PI SQL Client can be deployed in various combinations, but requires PI SQL Data Access Server (RTQP Engine) to
connect to the PI System. For details, see the PI SQL Data Access Server (RTQP Engine) Administrator Guide.
PI SQL Client can run on different architectures (32-bit or 64-bit).
Note: OSIsoft recommends using 64-bit operating systems whenever possible. Performance will be better on a
64-bit operating system than on a 32-bit operating system.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 7
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
System requirements
Operating Systems
PI SQL Client ODBC is supported on the following operating systems:
• Windows 8.1
• Windows 10
• Windows 11
• Windows Server 2012
• Windows Server 2012 R2
• Windows Server 2016
• Windows Server 2019
• Windows Server 2022
Server Platforms
This release supports connections to PI Server 2018 and later when PI SQL Data Access Server (RTQP Engine) is
installed and running on the server.
For more details about the PI SQL Client release you are using, see the PI SQL Client Release Notes available at
OSIsoft Customer Portal Products page.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 8
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
Note: Catalog files are separate downloadable files, and are used for application whitelisting. If you use
whitelisting, install the catalog files associated with your OSIsoft products to ensure that those products
function as intended. Windows catalog files that have been digitally signed by OSIsoft can be used as a digital
signature for 3rd party and other unsigned components installed by OSIsoft setup kits. This facilitates a
trusted way to verify these components and may be used for whitelisting purposes. For information on how
to use catalog files for whitelisting, refer to the OSIsoft Knowledge Base article: Whitelisting PI applications
based on catalog files.
Procedure
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 9
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
The setup kit also contains a file named silent.ini that contains modifications to setup.ini that are typically
needed to run a silent installation. You can augment the modification arguments by adding any of the options
described in the table below.
Note: Individual arguments must contain no spaces unless they are surrounded by quotes.
Command-line installation arguments
Argument Description
/i Specifies an installation.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 10
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
Note: Use single quotes (') around the directory path to allow for spaces in the folder names.
3. Type .\iPiSql.ps1 and press Enter.
You can specify the connection string when you call the tool as follows:
PS PIHOME\SQL\SQL Client\ODBC\Tools> .\iPiSql.ps1 -connectionString "Driver=PI SQL
Client;
AF Server=myAfServer; AF Database=myAfDatabase; Integrated Security=SSPI;"
4. If you did not specify the connection string, enter the following parameters:
• PI Asset Framework Server Name
• PI Asset Framework Database Name
If the installation was successful, you should see results similar to the following:
Connected to PI SQL Data Access Server (RTQP Engine) 2018 SP3 Patch 3, 1.8.21196.1
Driver name: PI SQL Client, version: 4.2.22020.1.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 11
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
1. In the Windows start menu, click Control Panel > Programs and Features, right-click on PI SQL Client ODBC
2021 (x64) and select Uninstall.
The selected component is removed.
2. In the Windows start menu, click Control Panel > Programs and Features, right-click on PI SQL Client ODBC
2021 (x86) and select Uninstall.
The selected component is removed.
Connection to PI AF Server
PI SQL Client ODBC allows applications to access the PI System through ODBC. Applications can be the iPiSql test
application provided with the PI SQL Client ODBC installation, a third-party application such as Microsoft Excel, or
an application you have developed.
You can define the ODBC connection using the following methods:
The type of connection needed is determined by the application that you are using.
To test the connection do one of the following:
The TrustedServersOnly registry key, located at HKLM\SOFTWARE\PISystem\PI SQL Client, enables or disables
HTTPS connection to a server with an untrusted certificate. For backward compatibility, the TrustedServersOnly
key is set to 0 by default, which allows connections to servers that use a certificate that is not in the trusted
certificates list of the client machine. As a security best practice, OSIsoft recommends that you set it to 1 to
prevent these connections.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 12
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
depending on the type of DSN, the ID and password of the user. Once a DSN is configured, the ODBC client can
reference it to make the connection.
In contrast, a connection that does not use a DSN requires that all the connection information be specified
within the ODBC client using a connection string.
DSNs can be configured using the ODBC Data Source Administrator. On a 64-bit Windows system, there is a 32-
bit and a 64-bit ODBC Data Source Administrator so that DSNs for 32-bit connections and 64-bit connections can
be configured separately.
To configure a DSN for PI SQL Client ODBC, open the ODBC Data Source Administrator on your machine. Select
the tab for the type of DSN you want and click Add. Select PI SQL Client, click Finish, and then complete the
fields on the PI ODBC DSN Configuration window.
ODBC Data Source definition
The following table provides details about the fields in the ODBC Data Source area of the PI ODBC DSN
Configuration window for PI SQL Client.
Field Description
Name A unique name identifying the DSN. Once you save the
DSN, you cannot change the name.
Connection tab
The following table provides details about the fields on the Connection tab.
Field Description
Trusted Connection Check this box to specify that the driver will request a
secure (or trusted) connection to a PI SQL Data Access
Server (RTQP Engine) instance. When selected, PI SQL
Client ODBC uses integrated login security to establish
connections using this data source. Any login ID or
password supplied is ignored.
Advanced tab
The following table provides details about the fields on the Advanced tab.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 13
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
Field Description
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 14
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
Network Define the network protocols to use and set the order
in which to use them.
By default, there are two protocols defined: one for
HTTPS on port 5464 and one for Net.TCP on port 5465.
You can have one of each type defined. If you do not
want to use a protocol, delete it to remove it from the
list.
Click on a protocol to select it, then click the button
for the action you want to perform.
Workarounds tab
The following table provides details about the fields on the Workarounds tab.
Field Description
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 15
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
The following examples show the syntax for the connection string:
Driver=PI SQL Client; AF Server=myAfServer; AF Database=myAfDatabase; Integrated
Security=SSPI;
Driver=PI SQL Client; Location=myAfServer; Data Source=myAfDatabase; Integrated
Security=SSPI;
Connection string keywords
The following table lists available keywords for the PI SQL Client ODBC connection string.
Time Zone Defaults to Local. You can set a Time Zone=(UTC-08:00) Pacific
specific time zone used for parsing Time (US & Canada)
of timestamp literals and for Time Zone=Local
rendering of timestamp column
values.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 16
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
Maximum string size Specifies the maximum string size Maximum string size=2000;
to be returned, because some
clients may not handle long string
correctly. Use 0 for unlimited size.
Defaults to 4000.
Data types
PI SQL Client ODBC supports the following data types:
AnsiString SQL_C_CHAR
AnsiStringCs SQL_C_CHAR
Boolean SQL_C_BIT
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 17
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
DateTime SQL_C_TYPE_TIMESTAMP
Double SQL_C_DOUBLE
Guid SQL_C_GUID
Note: If Guid as String is used in the DSN or
connection string, this is SQl_C_WCHAR instead.
Int8 SQL_C_TINYINT
Int16 SQL_C_SHORT
Int32 SQL_C_LONG
Int64 SQL_C_BIGINT
Single SQL_C_FLOAT
String SQL_C_WCHAR
StringCs SQL_C_WCHAR
TimeSpan SQL_C_TIME
UInt8 SQL_C_UTINYINT
UInt16 SQL_C_USHORT
UInt32 SQL_C_ULONG
UInt64 SQL_C_UBIGINT
Variant SQL_SS_VARIANT
Note: If Variant as String is used in the DSN or
connection string, this is SQL_C_WCHAR instead.
Note: PI SQL Client ODBC supports columns that have DBTYPE_VARIANT as the underlying OLE DB data type. PI
SQL Client ODBC uses the same approach as Microsoft ODBC drivers and the underlying SQL Server data type
sql_variant.
Applications developed in .NET using namespace System.Data.ODBC automatically recognize an Object column.
You can use the GetType method to recognize the contained subtype.
For native code applications, details can be found in the technet article, Mapping Data Types (ODBC).
Applications that use binding usually bind the column to a string data type.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 18
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
Multiple connections
Multiple connections from one PI SQL Client ODBC application to different PI SQL Data Access Server (RTQP
Engine) (installed on multiple nodes) are supported.
Messaging features
PI SQL Client ODBC uses Event Tracing for Windows (ETW) for function tracing and event logging.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 19
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
3. In the left pane, expand Applications and Services Log > OSIsoft > SQL > PI SQL Client ODBC > Debug
Channel.
4. Right-click Debug and select Enable Log.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 20
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
Now all PI SQL Client ODBC activity gets logged. Use any Event Tracing for Windows (ETW) tool for analyzing the
trace events.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 21
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 22
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
PI SQL Commander Lite includes a Query Compendium that you can use to learn about and test PI SQL
Commander Lite without affecting your real data.
For more information or to get started with the Query Compendium, see the PI SQL Commander Lite User Guide.
Connect to
The following procedure describes how to connect to PI AF server using PI SQL Client ODBC through PI SQL
Commander Lite. You can use a DSN to establish this connection. For more information, see the PI SQL
Commander Lite User Guide.
1. To open PI SQL Commander Lite, click Start > All Programs > PI System > PI SQL Commander Lite (64-bit).
2. In the Object Explorer pane, expand ODBC Data Sources, right-click PI SQL Client and click Connect.
3. In the PI SQL Client ODBC Login window, in the AF Server field, type the name of your PI AF server machine.
4. In the AF Database field, type the name of the PI AF database or select one from the drop-down list.
Note: The drop-down list in the AF Database field is available only if PI Web API Core Services is installed.
5. In the Authentication area, provide credentials for a Windows user account or select Trusted Connection to
use your Windows credentials to connect to PI AF server.
6. Optional: Click the Advanced tab to specify additional connection parameters such as the initial catalog,
command timeout, or protocol order.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 23
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
Note: To access the various PI AF data sources, PI System data references, and so on, you must enter login
information for an account with valid permissions for the machine that runs PI AF server.
For more information, see the topic "Firewalls and PI AF Security" in the PI Asset Framework (PI AF)
Installation and Maintenance Guide available at the OSIsoft Customer Portal Products page.
7. Click OK.
A green arrow next to the data source icon indicates that the connection is successful.
Note: Installation of PI SQL Data Access Server (RTQP Engine) requires you to connect to the PI SQL Client.
For more information, see the PI SQL Data Access Server (RTQP Engine) Administrator Guide.
If PI SQL Data Access Server (RTQP Engine) is not installed or the PI AF Server machine is not accessible, you
should see an error similar to the following:
1. In the Object Explorer pane, expand the schema under ODBC Data Sources > PI SQL Client.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 24
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
2. In the Catalogs folder, right-click either a table or a view, and click Execute Predefined Query.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 25
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
Note: You can edit a sample query and save it as a customized query. For information about two additional
collections of sample queries that you can load onto your system using PI SQL Commander Lite, see the PI
SQL Commander Lite Help.
3. View the query in the Query pane and its results in the Results pane.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 26
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
Transactions
Manual transactions are not supported. Queries should be executed in auto-commit mode. If an application
cannot use auto-commit, be aware that queries are executed immediately and commit has no effect. This also
means that rollback has no effect.
Batch processing
Batch processing is currently not supported with the RTQP Engine.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 27
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
Troubleshooting
To identify solutions when PI SQL Client ODBC does not connect or does not get data, OSIsoft recommends that
you test components in the order they are used as described here:
1. Run PI SQL Data Access Server (RTQP Engine) interactively to see more information, debug output, or use the
PI SQL DAS (RTQP Engine) Event Log to check for error messages.
2. For more information, see the PI SQL Data Access Server (RTQP Engine) Administrator Guide.
Note: When PI SQL Data Access Server (RTQP Engine) is run interactively, Kerberos authentication cannot be
used.
3. For PI SQL Client ODBC, enable logging for the driver.
4. Install PI SQL Client ODBC on the same computer as PI SQL Data Access Server (RTQP Engine).
Successful connection
The following message occurs when a successful connection is established:
Connected to PI SQL Data Access Server (RTQP Engine) 2018 SP3 Patch 3, 1.8.21196.1
Driver name: PI SQL Client, version: 4.2.22020.1.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 28
PI SQL Client ODBC
PI SQL Client ODBC Administrator Guide
None of the protocols could be used to establish a connection using the provided user name
and password
The following error message occurs if the specified User ID, or Password, or both do not exist, or if the spelling is
wrong:
ERROR [08001] None of the protocols could be used to establish a connection using the
provided user name and password.
None of the protocols could be used to establish a connection using Windows Integrated
Security
The following error message occurs if Windows Integrated Security is not available for the specified data source:
ERROR [08001] None of the protocols could be used to establish a connection using Windows
Integrated Security.
Boost Libraries
PI SQL Client includes the Boost libraries.
gSOAP Library
PI SQL Client includes the gSOAP library.
Note: The license and copyright information documents are located in the PIHOME\SQL\SQL Client\ODBC\Doc
folder, where PIHOME is your PIPC installation directory.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 29
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 30
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
Deployment options
The gateway can be deployed with other components in various combinations. PI SQL Client ODBC and Oracle
Database Gateway for ODBC must be installed on the same Windows computer but other components can be
distributed on your network, as needed. These other components include:
Installation
To connect Oracle to a non-Oracle system through DG4ODBC for Windows:
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 31
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
• Install and configure the PI SQL Client ODBC driver on the computer where DG4ODBC for Windows is
installed.
• Configure Oracle:
a. Configure the gateway init file (init*.ora).
b. Configure Oracle Net for the gateway (listener.ora).
c. Configure the Oracle database for gateway access (tnsnames.ora).
• Create a database link.
Note: DG4ODBC can be installed as 32-bit version or 64-bit version.
1. Install the PI SQL Client ODBC driver on the machine where DG4ODBC for Windows is installed.
2. In the Windows ODBC Administrator, add a System ODBC data source (DSN) that connects to the target
database.
On 64-bit Windows systems, both 32-bit and 64-bit versions of ODBC Administrator are available. Make sure
you use the platform that corresponds to the DG4ODBC platform.
3. On the Workarounds tab, select Variant as String and set Maximum String Size to 1333.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 32
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
4. On the Connections tab, click Test Connection to test the connection to the data source.
Configure Oracle
To configure DG4ODBC for Windows, you must edit three files and restart the Oracle Listener. The files are:
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 33
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
• init<sid>.ora
• listener.ora
• tnsnames.ora
The init<sid>.ora file references the System ODBC data source that you added in the ODBC Administrator. You
manually add connection descriptors to tnsnames.ora, and then reference those in listener.ora.
Caution: An incorrect entry in these files can lead to connection failure.
Examples
# This is a sample agent init file that contains the HS parameters that are
# needed for the Database Gateway for ODBC
#
# HS init parameters
#
HS_FDS_CONNECT_INFO=pisqlclient
HS_FDS_TRACE_LEVEL=DEBUG
HS_FDS_TIMESTAMP_MAPPING=TIMESTAMP
#
# Environment variables required for the non-Oracle system
#
#set <envvar>=<value>
Where:
Parameter Description
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 34
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
Examples
# listener.ora Network Configuration File:
C:\WINDOWS.X64_180000_db_home\NETWORK\ADMIN\listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(PROGRAM = dg4odbc)
(SID_NAME = pisqlclient)
(ORACLE_HOME = C:\WINDOWS.X64_180000_db_home)
)
…
Where:
Variable Description
SID_NAME The name of the gateway init file without the init
prefix or ora extension. In the example, the init file is
named initpisqlclient, and so pisqlclient is used as
the SID_NAME.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 35
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
Examples
# tnsnames.ora Network Configuration File:
C:\WINDOWS.X64_180000_db_home\NETWORK\ADMIN\tnsnames.ora
# Generated by Oracle configuration tools.
pi =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = ora2gtw.osisoft.int)(PORT = 1521))
)
(CONNECT_DATA =
(SID = pisqlclient)
)
(HS = OK)
)
…
Where:
Variable Description
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 36
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
SID Specifies the SID of the gateway and matches the SID
specified in the listener.ora file of the Oracle Net
Listener that is listening for the gateway.
Stop and start the Oracle Net Listener for the gateway
You must stop and restart the Oracle Net Listener to initiate the new settings.
Note: For configuration of multiple listeners or multiple ODBC data sources, consult the Oracle Database
Gateway Installation and Configuration Guide.
1. From the Start menu, select Settings > Control Panel > Services.
2. Select the Oracle Net Listener service for the gateway.
3. If the service is already running, click Stop to stop it.
4. Click Start to start or restart the service.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 37
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
1. To enable the TO_NCHAR capability, connect to SQL*Plus as if connecting to your regular database, using the
sysdba account.
2. At the SQL prompt, load the stored procedure called enable_to_nchar.sql that is provided in the samples
directory, PIHOME\SQL\SQL Client\ODBC\Samples\Oracle.
Examples
The following example shows the enable_to_nchar.sql stored procedure:
SQL*Plus: Release 18.0.0.0.0 - Production on Tue May 7 12:26:40 2019
Version 18.3.0.0.0
Connected to:
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 38
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 – Production Version 18.3.0.0.0
SQL>
• Configure an ODBC DSN, select the Variant as String workaround and set the Maximum String Size value to
1333.
• Create an init<sid>.ora file that includes the following specific setting:
HS_FDS_TIMESTAMP_MAPPING = TIMESTAMP
• Reference ODBC sid in listener.ora and tnsnames.ora (all standard, no specifics for PI SQL Client ODBC).
• Create the Database Link (all standard, no specifics for PI SQL Client ODBC).
• Enable the TO_NCHAR capability.
• Take special care when constraining string type columns.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 39
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 40
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 41
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 42
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
loop
v_ret:=dbms_hs_passthrough.fetch_row@pi(v_cursor,false);
EXIT WHEN v_ret = 0;
dbms_hs_passthrough.get_value@pi(v_cursor,1,v_elementname);
dbms_hs_passthrough.get_value@pi(v_cursor,2,v_attributename);
dbms_hs_passthrough.get_value@pi(v_cursor,3,v_time);
dbms_hs_passthrough.get_value@pi(v_cursor,4,v_value);
dbms_hs_passthrough.get_value@pi(v_cursor,5,v_value2);
dbms_output.put_line('Element '||v_elementname);
dbms_output.put_line('Attribute '||v_attributename);
dbms_output.put_line('TimeStamp '|| to_char(v_time,
'DD-MON-YYYY HH24:MI:SS.FF3'));
dbms_output.put_line('Value '|| v_value);
dbms_output.put_line('Value_Double '|| v_value2);
end loop;
dbms_hs_passthrough.close_cursor@pi(v_cursor);
end;
/
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 43
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 44
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
Variant columns
Columns that hold data of different data types are exposed as SQL_VARIANT in PI SQL Client ODBC. For example,
this is true for most Value columns. The Oracle Database Gateway for ODBC (DG4ODBC) does not support this
data type. The Oracle behavior for unknown data types is such that these columns are treated as nonexistent,
meaning you can neither retrieve nor constrain such columns.
PI SQL Client ODBC offers a workaround for the problem and allows you to expose SQL_VARIANT as a Unicode
string instead. While this allows you to include these columns in the SELECT list, constraining these columns has
several issues, which are described in the following sections.
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 45
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 46
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
Timestamp conditions
An issue exists when querying tables and using a timestep condition. In the following example, the timestamp is
specified without subseconds. Oracle parametrizes the timestep column using a Timestamp ODBC data type. This
Timestamp contains dirty subseconds as shown by the trace file, which leads to an unexpected result. In the
example query, the value timestamp returned is different than the one specified in the condition.
Examples:
-- The following PI SQL View is created using PI SQL Commander
CREATE VIEW [Master].[Element].[SampledValueView]
AS
SELECT "@time" time, sv."value", CAST("@time" AS "string") "time2", ea.Name "Name"
FROM [Master].[Element].[ft_GetSampledValue] sv
INNER JOIN [Master].[Element].[Attribute] ea ON ea.ID = sv.[@AttributeID]
WHERE ea.Element = 'B-210'
-- This query is executed using Oracle SQL Developer
SELECT "time" time1, "value" value, "time2" time2
FROM SampledValueView@pi
WHERE "Name" = 'Water Flow' AND "time" = '21-Apr-2019 12:30:00'
Result:
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 47
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
The trace file shows that subseconds are part of the timestamp parameter value being passed:
.
.
.
SQL text from hgopars, id=1, len=75 ...
00: 53454C45 43542022 74696D65 222C2276 [SELECT "time","v]
10: 616C7565 222C2274 696D6532 222C224E [alue","time2","N]
20: 616D6522 2046524F 4D202253 414D504C [ame" FROM "SAMPL]
30: 45445641 4C554556 49455722 20574845 [EDVALUEVIEW" WHE]
40: 52452022 74696D65 223D3F [RE "time"=?]
Exiting hgopars, rc=0 at 2019/05/13-16:05:15
Entered hgoopen, cursor id 1 at 2019/05/13-16:05:15
hgoopen, line 89: Printing hoada @ 000000C7E2DBEFD0
MAX:1, ACTUAL:1, BRC:1, WHT=3 (BIND_LIST)
DTY NULL-OK LEN MAXBUFLEN PR/SC CST IND MOD NAME
93 TIMESTAMP N 16 0 0/ 0 0 0 0 ?
Entered hgoprbv at 2019/05/13-16:05:16
hgoprbv, line 216: Printing hoada @ 000000C7E2DBEFD0
MAX:1, ACTUAL:1, BRC:1, WHT=3 (BIND_LIST)
DTY NULL-OK LEN MAXBUFLEN PR/SC CST IND MOD NAME
93 TIMESTAMP N 16 0 0/ 0 0 0 0 ?
Entered WP_SQLBindParameter at 2019/05/13-16:05:16
ParameterNumber 1, InputOutputType 1, ValueType 93, ParameterType 93,
ColumnSize 28, DecimalDigits 8, BufferLength 16,StrLen_or_IndPtr 0x000000C7E2DBEE90 (*0x10)
(Array size: 1)
16 bytes of data at 0x000000C7C9B14D50....
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 48
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
.
.
Now the corresponding trace file shows no subseconds for the timestamp parameter value being passed:
.
.
.
SQL text from hgopars, id=1, len=75 ...
00: 53454C45 43542022 74696D65 222C2276 [SELECT "time","v]
10: 616C7565 222C2274 696D6532 222C224E [alue","time2","N]
20: 616D6522 2046524F 4D202253 414D504C [ame" FROM "SAMPL]
30: 45445641 4C554556 49455722 20574845 [EDVALUEVIEW" WHE]
40: 52452022 74696D65 223D3F [RE "time"=?]
Exiting hgopars, rc=0 at 2019/05/13-15:55:48
Entered hgoopen, cursor id 1 at 2019/05/13-15:55:48
hgoopen, line 89: Printing hoada @ 00000090F7320A58
MAX:1, ACTUAL:1, BRC:1, WHT=3 (BIND_LIST)
DTY NULL-OK LEN MAXBUFLEN PR/SC CST IND MOD NAME
93 TIMESTAMP N 16 0 0/ 0 0 0 0 ?
Entered hgoprbv at 2019/05/13-15:55:48
hgoprbv, line 216: Printing hoada @ 00000090F7320A58
MAX:1, ACTUAL:1, BRC:1, WHT=3 (BIND_LIST)
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 49
PI SQL Client ODBC
PI SQL Client ODBC and Oracle Database Gateway Configuration Guide
Oracle resources
The following table lists relevant Oracle documentation.
Document Note
Database Gateway Installation and Configuration Note especially the following sections:
Guide
• Installing Oracle Database Gateway for ODBC
• Configuring Oracle Database Gateway for ODBC
• Installation Parameters
Database Gateway for ODBC User's Guide Contains information about the Oracle Database
Gateway for ODBC.
Oracle Database Heterogeneous Connectivity User's Contains information about how to optimize
Guide heterogeneous queries.
Oracle Database SQL Language Reference Note especially the CREATE DATABASE LINK section.
Logging options
For performance reasons and to understand unexpected results, it is very important to recognize the difference
between the heterogeneous query that is executed in the Oracle client and the remote query that is executed by
the Oracle Database Gateway.
The remote query is visible at various levels by using logging options:
©2023 AVEVA Group plc and its subsidiaries. All rights reserved. Page 50
AVEVA Group plc Tel +44 (0)1223 556655
High Cross
Madingley Road
Cambridge
CB3 0HB www.aveva.com
UK To find your local AVEVA office, visit www.aveva.com/offices
AVEVA believes the information in this publication is correct as of its publication date. As part of continued product development, such information is subject to
change without prior notice and is related to the current software release. AVEVA is not responsible for any inadvertent errors. All product names mentioned are
the trademarks of their respective holders.