Microsoft Knowledge Base Email Alertz

This article provides a sample SQL script for creating a linked server to DB2 using sp_addlinkedserver, and issues a few queries to illustrate the Distributed Query Processing (DQP) using DB2OLEDB, the Microsoft OLE DB provider for DB2. Ple

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 222937 - Last Review: December 4, 2007 - Revision: 3.2

Creating a linked server to DB2 using Microsoft OLE DB provider for DB2

This article was previously published under Q222937

On This Page

SUMMARY

This article provides a sample SQL script for creating a linked server to DB2 using sp_addlinkedserver, and issues a few queries to illustrate the Distributed Query Processing (DQP) using DB2OLEDB, the Microsoft OLE DB provider for DB2. Please refer to the following article in the Microsoft Knowledge Base for information on the keywords used in the DB2OLEDB initstring.
218590  (http://kbalertz.com/Feedback.aspx?kbNumber=218590/ ) Configuring data sources for the Microsoft OLE DB provider for DB2

Creating Linked Server

EXEC sp_addlinkedserver
@server = 'WNW3XX',
@srvproduct = 'Microsoft OLE DB Provider for DB2',
@catalog = 'OLYMPIA',
@provider = 'DB2OLEDB',
@provstr='NetLib=SNA;NetAddr=;NetPort=;RemoteLU=OLYMPIA;LocalLU=LOCAL;ModeName=QPCSUPP;User ID=WNW3XX;Password=WNW3XX;InitCat=OLYMPIA;Default Schema=WNW3XX;PkgCol=WNW3XX;TPName=;Commit=YES;IsoLvl=NC;AccMode=;CCSID=37;PCCodePage=1252;BinAsChar=NO;Data Source=Olympia_WNW3XX'

EXEC sp_addlinkedsrvlogin 'WNW3XX', false, NULL, 'WNW3XX', 'WNW3XX'
				
Please note that:
  • DB2OLEDB provider needs to run in-proc. To enable this setting:
    1. Start the Microsoft SQL Server Enterprise Manager.
    2. In the Console tree, find the Linked Servers node (under the Security folder). Right-click on the linked server created above, and in the Properties dialog box, click the General tab, then click on Options, and click to enable the Allow InProcess setting. This is the only way to enable this setting, and after it has been enabled for a given provider, the setting is used for every subsequent linked server created using that provider, including the ones created with T-SQL script.
  • The total length of the linked server initstring must be no more than 278 characters, so it is advantageous to use the DB2OLEDB short connection string arguments as documented above.
  • Linked Servers using DB2OLEDB can also be configured to connect over TCP/IP, though the above script illustrates this using an SNA APPC connection.

Sample Distributed Queries

Example of SELECT using 4-part name: LinkedServer.Catalog.Schema.Table
SELECT * FROM WNW3XX.OLYMPIA.WNW3XX.DEPARTMENT

Example of Pass Through SELECT using OPENQUERY with 3-part name:
SELECT * FROM OPENQUERY(WNW3XX,"SELECT * FROM OLYMPIA.WNW3XX.EMP_ACT")

Example of Pass Through SELECT using OPENROWSET with 2-part name:
SELECT * FROM OPENROWSET
('DB2OLEDB',Netlib=SNA;NetAddr=;NetPort=;RemoteLU=OLYMPIA;LocalLU=LOCAL;ModeName=QPCSUPP;User ID=WNW3XX;Password=WNW3XX;InitCat=OLYMPIA;Default Schema=WNW3XX;PkgCol=WNW3XX;TPName=;Commit=YES;IsoLvl=NC;AccMode=;CCSID=37;PCCodePage=1252;BinAsChar=NO;Data Source=Sample',
'SELECT * FROM WNW3XX.EMPLOYEE' )

Example of an INSERT using 4-part name:
INSERT INTO WNW3XX.OLYMPIA.WNW3XX.DEPARTMENT VALUES
('E21','DUMMY',NULL,'E01')

Note that UPDATE and DELETE using DQP are not possible with the DB2OLEDB provider that shipped with SNA version 4.0 Service Pack 2 and Service Pack 3 due to lack of bookmark support, but these do work with the SNA 4.0 Service Pack 4 provider and the provider that shipped with Host Integration Server. For more information on this, see the following article in the Microsoft Knowledge Base:

287093  (http://kbalertz.com/Feedback.aspx?kbNumber=287093/EN-US/ ) DB2OLEDB Supports UPDATE/DELETE from SQL Linked Server
Example of JOIN between a SQLServer and DB2 table:
SELECT A.EMPLOYEE_NUMBER,B.ACTNO FROM CORPDATA..EMPLOYEE_ACCOUNT A, WNW3XX.OLYMPIA.WNW3XX.EMP_ACT B WHERE A.EMPLOYEE_NUMBER = B.EMPNO ORDER BY A.EMPLOYEE_NUMBER

APPLIES TO
  • Microsoft OLE DB Provider for DB2
  • Microsoft Host Integration Server 2000 Standard Edition
  • Microsoft SNA Server 4.0 Service Pack 4
  • Microsoft Host Integration Server 2004 Standard Edition
Keywords: 
kbinfo KB222937
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate