ODBC Interface User Guide PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

ODBC Interface User Guide

This document describes how to install and use the PipelineStudio® ODBC Interface on your
computer.

Contents
Contents ............................................................................................................................... 1
Requirements ....................................................................................................................... 1
PipelineStudio Microsoft SQL Server Database Installation .................................................. 2
PipelineStudio User DSN (Data Source Name) Setup........................................................... 5
Saving PipelineStudio Configuration Data to a Microsoft SQL Server® Database ............... 11
Creating Reports using Microsoft Excel® and a Microsoft SQL Server® Database ............... 14

Database Stored Procedures .......................................................................................... 14


Installing the Stored Procedures ..................................................................................... 15
Using the Stored Procedures in Microsoft Excel® ............................................................ 17

Troubleshooting .................................................................................................................. 22
Notation .............................................................................................................................. 22

Requirements
To view reports generated by ODBC database you need to have Microsoft SQL Server®
(2008, 2012 or 2014) or Microsoft SQL Server Express® (2008, 2012 or 2014) installed on
your local machine or network, as well as, Microsoft SQL Server Management Studio®.
Please refer to your IT department if you are not sure about the installation process.

After installing Microsoft SQL Server®, please verify that your domain account has been
added to the list of “Logins” defined with “Windows Authentication” inside of SQL Server.
You will need to use the Microsoft SQL Server Management Studio® or must be connected
to an already existing database to perform the next few tasks.

Note: “Windows Authentication” and not “SQL Server Authentication” must be used for this
connectivity

1
PipelineStudio Microsoft SQL Server Database Installation
First start Microsoft SQL Server Management Studio® and create a new database where
the data will be stored. This is as simple as selecting “New Database…” from the Object
Explorer, following the prompts and accepting the default values:

Select a name for the database. See below example database name as PLS:

2
Then you will need to run the SQL script called “PreCreateTablesAndIndexesScript.sql“.
This script is located in the directory “My Documents\My Simulations\ODBC”

 Save the PreCreateTablesAndIndexesScript.sql file somewhere on your computer


 Open the PreCreateTablesAndIndexesScript.sql file that you saved in Microsoft SQL
Server Management Studio, or alternatively drag the file into the Microsoft SQL
Server Management Studio® window
 Select the database created earlier in the Object Explorer window (e.g. PLS), ensure
that the database that you created is shown in the Available Databases dropdown
(shown highlighted below):

3
 Click the “! Execute” button on the toolbar. This will run the script which will create
the required tables/indexes:

4
PipelineStudio User DSN (Data Source Name) Setup
It is necessary to configure the User DSN (Data Source Name) that PipelineStudio will use
to communicate with the database. This can be done via Data Sources (ODBC).
To locate this from the Control Panel, switch the Control Panel view to „Small icons‟ (as
shown below):

Choose “Administrative Tools”:

5
Choose “Data Sources (ODBC)”:

Select “Add” from the “User DSN” tab:

6
From the “Create New Data Source” window select the SQL Server driver to set up the
data source:

Give the data source a name (e.g. PLS) and select the server which you want to connect to
(for example ...\SQLEXPRESS) and then select “Next”

7
Select the authentication preference from the “Create a New Data Source to SQL Server”
window:

Select the default database to use. You MUST change the default database connection to
the database that you created at the beginning of this exercise. See example below
database name as PLS. The default setting is for the “master” database and this value must
be changed.

8
Select “Next” to complete adding/creating the data source:

Select “Finish” and test the data source connection from the “Test Data Source…” option:

9
If the connection is established successfully, you should be able to see the “TESTS
COMPLETED SUCCESSFULLY!” message from the “SQL Server ODBC Data Source
Test” window:

10
Saving PipelineStudio Configuration Data to a Microsoft
SQL Server® Database
Once a User DSN has been created ready for use within PipelineStudio you can connect
your configuration to the Microsoft SQL Database by using the configuration option under
“Simulation  Options…” in PipelineStudio

 Open the configuration and select “Simulation  Options…”

11
 The “General” tab of the Simulation Options dialog will allow you to create this
connection. From the “General” tab, select the “Save configuration and report
data to database” checkbox (highlighted below):

12
 Select the ODBC Data Source created earlier (e.g. PLS) from the Data source
dropdown:

 PipelineStudio configuration and report data will now be saved to the Microsoft SQL
Database for that configuration. You can toggle the database connection “On” or
“Off” by changing the “Save configuration and report data to database” checkbox
setting. It is recommended that users making a lot of configuration changes and
subsequent file saves leave this checkbox unselected until they are ready to start
saving results to the Microsoft SQL Database.

13
Creating Reports using Microsoft Excel® and a Microsoft
SQL Server® Database
Here are some pointers which can be used to create reports using Microsoft Excel® and a
Microsoft SQL database.

Prerequisites
 Macros enabled
 VBA project access

Database Stored Procedures

There is an SQL Script provided with the installation with stored procedures which can be
added to your database to help retrieve configuration and report data from the database in a
meaningful format.
The following procedures have been made available:

PLSGetConfigData "Config Name", "Element Type"


This returns a table with all the configuration data for all elements of the given type in
the given configuration.
Example
PLSGetConfigData "Demo", "pipe"

PLSGetReportData "Config Name", "Element Type"


This returns a table with all the report data for all elements of the given type in the
given configuration.
Example
PLSGetReportData "Demo", "pipe"

PLSGetConfigDataForProps "Config Name", "Element Type", "List of


Keywords"
This returns a table with configuration data for the listed keywords, for all elements of
the given type in the given configuration.
Example
PLSGetConfigDataForProps "Demo", "pipe", "name,l,_id, rough,eff, gaseq, atemp, u,
wt, drag"

PLSGetReportDataForProps "Config Name", "Element Type", "List of


Keywords"
This returns a table with report data for the listed keywords, for all elements of the
given type in the given configuration.
Example

14
PLSGetReportDataForProps "Demo", "pipe", "currstatus, currpresup, currpresdn,
currflowup, currflowdn, currtempup, currtempdn"

Installing the Stored Procedures

The SQL script provided is called Create_Stored_Procedures_Script.sql. This script is


located in the directory “Documents\My Simulations\ODBC”
Note: Before you run the above script, you must change the database name to use the
database name created at the beginning of this exercise on the first line where it says USE
[PutYourDatabaseNameHere].

 Save the Create_Stored_Procedures_Script.sql file somewhere on your computer


 Open the Create_Stored_Procedures_Script.sql file that you saved in Microsoft SQL
Server Management Studio®, or alternatively drag the file into the Microsoft SQL
Server Management Studio® window
 Change the database name to use the database created earlier on the first line
where it says USE [PutYourDatabaseNameHere], e.g. USE [PLS] and save the file
 Select and open the database created earlier in the Object Explorer window (e.g.
PLS) so that you can see your database:

15
 Click the “! Execute” button on the toolbar. This will run the script which will create
the stored procedures:

16
 Check the stored procedures were created correctly by opening the Programmability
folder and Stored Procedures folder. You may have to click the refresh button if the
folders were already open when you ran the script:

Using the Stored Procedures in Microsoft Excel®

Several example .xlsm files are located in the folder “Documents\My Simulations\ODBC”:
 PLS DB Demo Gas.xlsm
 PLS DB Demo Liquid.xlsm
 PLS DB Reports Gas.xlsm
 PLS DB Reports Liquid.xlsm
These are separate report examples for both Gas and Liquid configurations.

It is recommended that the installed version of Excel has trusted access to the VBA project
model and that macros are enabled.

17
 Start Microsoft Excel® and open the example file. Your database connection name may
not be the default value, in which case you should be prompted to choose a connection.
Choose the data source created earlier (e.g. PLS) from the list:

 Click OK on the “SQL Server Login” dialog:

18
 If there is a Security Warning that database connections have been disabled, click the
button to Enable Content:

19
 Now you can change the Configuration name and Element Type to get the configuration
and report data from the database. After changing the settings click on the Load Data
button:

20
 The Report sheet will show the output data:

21
Troubleshooting
Should you encounter any problems please contact the PipelineStudio technical support
team at ESI.Support@emerson.com.

Notation
PipelineStudio, TNet and Energy Solutions are registered trademarks of Energy Solutions International.

Windows, Excel and SQL Server are registered trademarks of Microsoft Corporation.

Intel is a registered trademark of Intel Corporation.

SentinelRMS* © 1989-2008 SafeNet, Inc. All rights reserved


SafeNet, Sentinel, SentinelLM, and Sentinel RMS are either trademarks or registered trademarks of SafeNet, Inc.

All other product names referenced herein are trademarks or registered trademarks of their respective
manufacturers.

22

You might also like