YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Reusable PI-ODBC connection Options · View
RJK Solutions
#1 Posted : Tuesday, November 04, 2008 9:46:29 AM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 612
Location: Cheshire, United Kingdom.
In this topic we will create a reusable connection to PI via the PI-ODBC driver. The connection method is standardised to be used as and when needed to ensure the connection is still alive.

PI ODBC Client Overview

The PI ODBC Driver is used to bring process data into any ODBC-compliant client application.

Open Database Connectivity (ODBC) is Microsoft's implementation of the SQL Access Group's call level interface standard, with some enhancements. Relational database vendors following this standard can be assured that any standard ODBC client applications can access their data.

The PI ODBC Driver is especially useful for applications that combine PI System data with data from other sources, such as cost accounting or laboratory systems. PI ODBC supports Level 1 compliance to the ODBC API, which allows client applications to browse such catalog information as table and column names. The ODBC standard also specifies levels of compliance for SQL processing: OSI Software implements the Core SQL Grammar.

This product is not related to the features of PI ProcessBook (Version 1.2 or later), which uses other vendors' ODBC drivers to access and display data from foreign databases.

The PI ODBC Driver is part of the Data Access (DA) add-on license, which also includes the PI OPC HDA Server, and the PI OLEDB Provider. It is not available separately.

The Connection


Firstly, once you have installed the PI-ODBC driver, for ease you need to create a DSN. For this example the DSN was created with the name of "PI".

What needs to be achieved:
- A module/class level variable to hold the connection (ADODB.Connection)
- A method to evaluate the connection variable and connect via PI-ODBC if required.

How this is done in a VBA project, for example in MS Excel:

Code:
Private Conn As ADODB.Connection

Private Function PIODBC_Connection() As Boolean

On Error GoTo PIODBC_Connection_Error

If TypeName(Conn) = "Nothing" Then Set Conn = New ADODB.Connection
If Not Conn.State = adStateOpen Then Conn.Open "PI", "piuser", "pipass"
PIODBC_Connection = (Conn.State = adStateOpen)

Exit Function

PIODBC_Connection_Error:
PIODBC_Connection = False

End Function


To test the connection is established, create a method to call the connection method:

Code:
Sub TestingConnection()
   If PIODBC_Connection Then
      ' Connection established!
   Else

   End If
End Sub


Now this routine can be used whenever required and is used throughout any examples posted onto this forum.
Principal Consultant
Real-Time Data Management @ Wipro Technologies
Sponsor  
 

OSIsoft vCampus is a subscription-based, online offering that consists of providing everything people need to develop applications on the PI System.
We invite you to take a "tour" of the OSIsoft Virtual Campus - also feel free to consult the FAQ  or contact OSIsoft vCampus for more details.
RJK Solutions
#2 Posted : Tuesday, November 18, 2008 9:57:55 AM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 612
Location: Cheshire, United Kingdom.
Alternatively, you can create a connection without the use of a DSN:

Code:
Private Function PIODBC_Connection() As Boolean

On Error GoTo PIODBC_Connection_Error

If TypeName(Conn) = "Nothing" Then Set Conn = New ADODB.Connection
If Not Conn.State = adStateOpen Then Conn.Open "Driver={PI-ODBC}; Server=piserver; UID=piuser; PWD=pipass"
PIODBC_Connection = (Conn.State = adStateOpen)

Exit Function

PIODBC_Connection_Error:
PIODBC_Connection = False

End Function
Principal Consultant
Real-Time Data Management @ Wipro Technologies
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.