Export (0) Print
Expand All

OLE DB Provider for DB2

The Microsoft OLE DB Provider for DB2, distributed with Microsoft Host Integration Server 2004, allows for SQL Server 2005 distributed queries to query data in DB2 databases.

The OLE DB Provider for DB2 is included with SQL Server 2005. For information about how to install and configure the OLE DB provider, see the documentation that is included with the provider.

To create a linked server to access a DB2 database
  1. Install Host Integration Server 2004 Client software on a computer that is running an instance of SQL Server and select the options to install the OLE DB Provider for DB2.

  2. Determine the connection string the OLE DB Provider for DB2 requires to access the DB2 data source you want to query. The best way to determine a connection string is to build a Data Link file by using the Host Integration Server New OLE DB Data Source application. For more information, see the Microsoft Host Integration Server 2004 documentation.

  3. Execute sp_addlinkedserver to create a linked server, specifying DB2OLEDB as the provider_name, the name of the DB2 catalog that contains the data you want to access as catalog, and the connection string from step 2 as provider_string.

    The following example shows how to use sp_addlinkedserver to create a linked server definition that accesses a DB2 database:

    EXEC sp_addlinkedserver @server = 'DB2SRV',
       @srvproduct = 'Microsoft OLE DB Provider for DB2',
       @catalog = 'SEATTLE',
       @provider = 'DB2OLEDB',
       @provstr =
          Default Schema=WNW3XX;PkgCol=WNW3XX;TPName=;Commit=YES;
          Data Source=Seattle_WNW3XX'
  4. Execute sp_addlinkedsrvlogin to create login mappings from SQL Server 2005 logins to DB2 logins.

    The following example maps the SQL Server login SQLJoe to DB2 login DB2Joe:

    EXEC sp_addlinkedsrvlogin 'DB2SRV', false, 'SQLJoe', 'DB2Joe', 'x894jd03?'
    Passwords will be transmitted unencrypted. Passwords may be visible in data source definitions and scripts saved to disk, in backups, and in log files. Never use an administrator password in this kind of connection. Consult your network administrator for security guidance specific to your environment.

After you complete the previous steps, you can use the linked server name DB2SRV as the server name in four-part names and as linked_server in the OPENQUERY function. For example:




When the distributed queries against DB2 data sources involve NULL comparisons, use ISNULL or IS NOT NULL instead of comparison operators, such as equals (=), greater than (>), or less than (< ). Additionally, INSERT statements should supply values for all columns in a table, even if certain columns in the table can be NULL or have default values.

Community Additions

© 2014 Microsoft