36
Craig Pelkie [email protected] Copyright © 2014, Craig Pelkie ALL RIGHTS RESERVED Microsoft SQL Server for IBM i Developers

Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

  • Upload
    voanh

  • View
    243

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

Craig [email protected]

Copyright © 2014, Craig PelkieALL RIGHTS RESERVED

Microsoft SQL Server for IBM i Developers

Page 2: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

2

Outline of this meeting

• Overview of Microsoft SQL Server

• SQL Server Features

• The SQL Server Management Studio

• The SQL Server Configuration Manager

• IBM i Database Providers and SQL Server

• Linked Sever to the IBM i

• Connecting with JDBC from IBM i to SQL Server

• SQL Server Reporting Services

• SQL Server Integration Services

Page 3: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

3

What is Microsoft SQL Server?

• Windows database management system• Originally developed by Sybase• Microsoft / Sybase partnership through late 1980's• All-Microsoft product since early 1990's

• Versions of SQL Server• Obsolete and Older versions:

• SQL Server 6.5• SQL Server 7• SQL Server 2000• SQL Server 2005• SQL Server 2008• SQL Server 2008 R2

• Current versions:• SQL Server 2012• SQL Server 2014 CTP

Primary reference:http://www.microsoft.com/sql

Page 4: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

4

SQL Server 2012 Editions

http://www.microsoft.com/en-us/sqlserver/editions.aspx

Edition Features

SQL Server 2012 Express No-chargeNot included

SQL Server Analysis Services (SSAS)SQL Server Integration Service (SSIS)

SQL Server 2012 Standard Targeted for small/medium business

SQL Server 2012 Business Intelligence Includes all features of StandardFeatures for BI / Analysis

SQL Server 2012 Enterprise Includes all features of Business Intelligence

SQL Server 2012 Enterprise Evaluation 180-day evaluation

SQL Server 2012 Developer Includes all features of EnterpriseLicensed for development only

Page 5: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

SQL Server Features

5

Feature DescriptionSQL Server Database Services Core database engine

Replication – distribute data to multipledatabases

Full-text search – linguistic queries based on text data

Filestream — BLOB data stored in file system

SQL Server Analysis Services (SSAS) Online Analytical Processing (OLAP)

Data mining / Business Intelligence

SQL Server Reporting Services (SSRS) Web-based Report Manager / Report Server

Create / Manage / Distribute reports

Output to PDF / Word / Excel

SQL Server Integration Services (SSIS) Extract / Transform / Load (ETL) processing

Integrate data from multiple sources,to multiple destinations

Express Edition – can run but not create SSIS packages

Page 6: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

SQL Server Management Studio

6Object Explorer Editor / Results / Messages Properties

Page 7: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

SQL Server Configuration Manager

7

Page 8: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

Connection Options, IBM i Access for Windows

• IBM i Access for Windows

• Licensed Program Products

• 57xx-XW1 – IBM i Access Family

• 57xx-XE1 – IBM i Access for Windows

• These providers are no-chargecomponents of IBM i Access

• Can be installed independentlyof other IBM i Access components

• 3 OLE DB Providers are installed:IBMDA400 – SQL supportIBMDARLA – Record Level AccessIBMDASQL – SQL, transactions

Provider IBM i Access VRM

ODBC V5R1+OLE DB V5R1+.NET V5R3+

8

Caution: be sure to matchthe “bit-edness” with yourenvironment (32/64)

Page 9: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

Configure the IBMDA400 / IBMDASQL OLE DB provider

9

Go toServer Objects

Linked ServersProviders

IBMDA400 / IBMDASQL

Allow inprocess must be checkedfor the IBMDA400 / IBMDASQL

provider to work

Page 10: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

Run an OPENROWSET query to the IBM i

10

The OPENROWSET query proves that SQL Server can connect to your IBM i.

It proves that the OLE DB database provider is configured correctly and is functional.

SELECT * FROM OPENROWSET ('IBMDA400', 'M270' ; 'QUSER' ; 'QUSER' ,'SELECT * FROM QIWS.QCUSTCDT')

Page 11: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

SQL Server – Create a Linked Server

• Linked Server • Persistent object in SQL Server

• Represents a connection to another data source• Can be to another SQL Server• Can be to another type of database server that has an OLE DB Provider• OLE DB Provider is installed on the PC/server where SQL Server is installed

11

Page 12: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

Configure the Linked Server

Select the IBMDA400 Provider

(any value)

TCP/IP Host Name of IBM i to link to

Valid Provider String for IBMDA400

Name that will be used within SQL Server for the Linked Server

http://www.connectionstrings.com

12

Page 13: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

Trouble spot: Provider String

• Provider string that works for IBMDA400 / IBMDASQL

Catalog Library List=lib1,lib2,lib3,...;

• Notes• use spaces as separator in Catalog Library List keyword• use commas as delimiters in library list

• TO DO• IBM Technical Documentation pages on IBM i web site

Document Number 23062121

iSeries Access for Windows Custom Connection Properties for OLE DB

13

Page 14: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

Review the Linked Server

• After you create the linked server, expand the Linked Server item

• If you don't see the server, press F5 or use the View, Refresh menu item to refresh the SQL Server Object Explorer

• If you see your linked server, expand it to see your tables

14

Picks up the Relational Database Directory Entry as the "Catalog" nameWRKRDBDIRE - Work with Relational Database Directory Entry

Note: if you have IASPs, each IASP is considered to have its own "database"Those database names are listed under Catalogs in the Object Explorer

Page 15: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

Run a Query in SQL Server against a table in the Linked Server

15

SQL Server flags all of the column names (and the object name)as invalid in the Query Editor Window

Page 16: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

Results of running the query (pass 1)

16

SQL Server selects only the character data fields

Page 17: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

Results of running the query (pass 2)

17

Specify a SELECT * or the columns to select,the columns are now retrieved

Page 18: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

Create a SQL Server Database

18

Page 19: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

Populate a table in SQL Server with SELECT INTO from a Linked Server table

SELECT CUSNUM, LSTNAM, INIT, STREET

INTO SQL400.dbo.QCUST

FROM M270.S105HMNM.ADVWORKS.QCUSTCDT

Server name (TCP/IP Host Name)RDB name (WRKRDBDIRE)

Library nameTable name

19

Page 20: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

Saving a script in SQL Server

20

The script to be saved

Use the File, Save As menu toprompt for a save-to directory and name

Conventional extension: .sql

You can open the saved script file inSQL Server Management Studio.Click the Execute button to run it.

Page 21: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

Use the SQLCMD command to run a script

21

The sqlcmd command can be used to run a script file. The syntax for the command is:

sqlcmd -S server_name\instance_name -i c:\script_file_name.sql

where

-S identifies the following values as the server name and instance name

server_name - name of the SQL Server where the script is to be run

instance_name - is the instance of the SQL Server

-i identifies the following value as the name of the input file (the script)

c:\script_file_name.sql is the complete path and file name of the script file

Page 22: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

The Microsoft SQL Server JDBC driver

• No-charge download from Microsoft

http://msdn.microsoft.com/en-us/sqlserver/aa937724/

(or go to Microsoft.com, search for "SQL Server JDBC")

• Download

Microsoft SQL Server JDBC Driver 3.0sqljdbc.jar - Java 1.x, Java 5sqljdbc4.jar - requires Java 6.0

• Install the .jar file to a directory in the IFS

• Set CLASSPATH to the .jar

22

Page 23: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

Connect from IBM i using the JDBC Driver

23

private static ResultSet createResultSet(String customer) {

ResultSet rs = null;

try {Properties p = new Properties();p.put("user", "SQLTEST");p.put("Password", "sqltest");p.put("DatabaseName", "Northwind");

conn = DriverManager.getConnection("jdbc:sqlserver://host_name:1433", p);

stmt = conn.createStatement();

rs = stmt.executeQuery("SELECT * FROM Northwind.dbo.Customers");}

catch (Exception e) {System.err.println("Exception: " + e.getMessage());System.exit(EXIT_ERROR);

}

return rs;}

Page 24: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

Connect to SQL Server from RPG

• Primary reference:

• Scott Klement’s work and articles on iProDeveloper.com

• www.iprodeveloper.com

• Search for JDBCR4

• How it works• Download / install JDBC driver from Microsoft• Download / install Scott’s service program code, examples• Configure Java environment• Create RPG programs using the service program

24

Page 25: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

Connect to SQL Server from RPG

• Another tool:

• Dieter Bender’s AppServer4RPG and ArdGate (Application Request Driver)

• http://sourceforge.net/projects/appserver4rpg

• Also uses JDBC driver

• How it works• Download / install JDBC driver from Microsoft• Download / install AppServer4RPG code, samples• Configure Java environment• Create RPG programs using ArdGate API

25

Page 26: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

What is SQL Server Reporting Services?

• Managed Reporting• Recurring reports• Often collates data from multiple data sources

• Ad-Hoc Reporting• Typically end-user driven• Generally one-time, relatively simple, time-dependent

• Embedded Reporting• Reports embedded within business apps / portals• Examples

• Reports linked to SharePoint Server• Report output to Excel

26

Page 27: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

SSRS - Sample Report, list with sortable columns

27

This is a simple list-stylereport.

Many of the columns aresortable, by clicking thecolumn header text

Page 28: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

SSRS - Dynamic expand/collapse (drill–down)

28

This report uses dynamic expansion and collapse for row groups

Page 29: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

SSRS - Dynamic expand/collapse (drill–down) in Excel

29

Export the report to Excel, preserves the expand/collapse feature

Page 30: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

SSRS - Document Map report

30

The Document Mapis displayed to theleft of the content

A document map provides a quicknavigation tool through a lengthyreport

Page 31: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

SSRS - Summary data / graph / parameters

31

This shows a composite report that includes

• Parameters• Summarized data• Graphs

The summarized data and graphs can be drilled into to show the backing data.

Page 32: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

SSRS - Report Delivery: File formats

• SSRS can render into:• HTML• PDF• CSV• XML• Image (TIFF)• Microsoft Office Word• Microsoft Office Excel

• Reports rendered into Word / Excel are fully editable documents, users can create custom documents based on the report

• Reports can also be emailed from SSRS as a file attachment of one of the supported file formats

32

Page 33: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

SSRS - Report Delivery: Report Manager

33

The Report Manager is included with SSRS. It provides a web-based catalog of reports.

Users can view lists of reports they are allowed to access.

An alternative to Report Manager is SSRS integration with SharePoint Server.

Also, at least two appsavailable in Apple App Storefor iPhone / iPad

Page 34: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

What is SQL Server Integration Services?

• Historically known as Data Transformation Services (DTS)• SQL Server 7.0, SQL Server 2000• SSIS first released with SQL Server 2005

• Data Import / Export• Flat file / database -> database / flat file

• Extract, Transform, Load (ETL)• Typically associated with database -> data warehouse• Transform, clean, de-dupe, data conformance

• Control Flow Engine• Control sequential / scripted execution of sequence of events• Supports conditional processing, error handling• Examples

• Download / upload• Rename, drop, create, index builds, backup

34

Page 35: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

SSIS Package – Data Flow tasks

SSIS Package includes1..many Control Flow tasks

Dependencies between tasks can be set

Example: Task 1 must complete successfully before Task 2 runs

35

Page 36: Microsoft SQL Server for IBM i Developers - Web400.com · • SQL Server Integration Services. 3 ... (Exception e) {System.err.println ... Microsoft SQL Server for IBM i Developers

Summary

If you don't already have SQL Server in your shop

Or if you are working with an older version (SS 7, SS 2000, SS2005, SS 2008)

Consider downloading the SQL Server 2012 Express edition

Downloads for IBM i Access for Windows

http://www.web400.com/downloads/Verify_IBMiAccess_V5Rx_v2.pdf

http://www.web400.com/downloads/Verify_IBMiAccess_V7Rx.pdf

Configure IBMDA400 or IBMDASQL OLE DB providerTest OPENROWSET queryCreate/test linked server

36