Answered by:
Bulk Insert into DB2 from SQL Server 2005 Using Linked Server

Question
-
My database is in SQL Server 2005. I routinely upload data into a DB2 database using a linked server. Problem is that my query (see below) only uploads one record at a time. I have my stored procedure set up to loop through the records until all have been uploaded. I'd like to change this to a single bulk insert query. I've tried it and get an error that reads, "Server '[Server Name]' is not configured for RPC." Our DB2 DBAs are telling me that this is a Microsoft issue and that there isn't anything they can do at their end to correct it. Any suggestions? Here is the SQL:
-- Insert data into SSD_MBL_DEV table and then upload to DB2
DECLARE @mainLoopControl int, @NextDevice int, @WS_ID varchar(11)
SET @mainLoopControl = 1
WHILE @mainLoopControl = 1
BEGIN
SELECT @NextDevice = MIN(CAST(RIGHT(WS_ID,5) AS int))
FROM MCC_Import WHERE HH4 = 1 AND (WS_ID LIKE 'PEPCUH%' AND LEN(WS_ID) = 11)
AND Environment = 'PROD' AND WS_ID NOT IN (SELECT DEV_NM FROM OPENQUERY(SSDDEV3,'SELECT DEV_NM from SSD.MBL_DEV'))
SELECT @WS_ID = WS_ID
FROM MCC_Import WHERE CAST(RIGHT(WS_ID,5) AS int) = @NextDevice
INSERT INTO SSD_MBL_DEV (DEV_NM, MDL_NM, DPLOY_STAT_TS, LAST_UPDT_TS, LAST_UPDT_USEID)
SELECT WS_ID, Model_Type, GETDATE(), GETDATE(), Tech_Name FROM MCC_Import WHERE WS_ID = @WS_ID DECLARE @DEV_NM varchar(11), @MFG_NM varchar(25), @MDL_NM varchar(25), @OS_NM varchar(32), @OS_VRSN varchar(24), @SER_NBR varchar(11), @DEV_TYPE_CODE char(3), @DPLOY_STAT_CODE smallint, @DPLOY_STAT_TS smalldatetime, @CTRY_CODE char(3), @CO_CODE char(3), @RT_NBR int, @STRUC_NODE_SYS_NBR char(6), @LAST_UPDT_TS smalldatetime, @LAST_UPDT_USEID varchar(12)
SELECT @DEV_NM = (SELECT DEV_NM FROM SSD_MBL_DEV),
@MFG_NM = (SELECT MFG_NM FROM SSD_MBL_DEV),
@MDL_NM = (SELECT MDL_NM FROM SSD_MBL_DEV),
@OS_NM = (SELECT OS_NM FROM SSD_MBL_DEV),
@OS_VRSN = (SELECT OS_VRSN FROM SSD_MBL_DEV),
@SER_NBR = (SELECT SER_NBR FROM SSD_MBL_DEV),
@DEV_TYPE_CODE = (SELECT DEV_TYPE_CODE FROM SSD_MBL_DEV),
@DPLOY_STAT_CODE = (SELECT DPLOY_STAT_CODE FROM SSD_MBL_DEV),
@DPLOY_STAT_TS = (SELECT DPLOY_STAT_TS FROM SSD_MBL_DEV),
@CTRY_CODE = (SELECT CTRY_CODE FROM SSD_MBL_DEV),
@CO_CODE = (SELECT CO_CODE FROM SSD_MBL_DEV),
@RT_NBR = (SELECT RT_NBR FROM SSD_MBL_DEV),
@STRUC_NODE_SYS_NBR = (SELECT STRUC_NODE_SYS_NBR FROM SSD_MBL_DEV),
@LAST_UPDT_TS = (SELECT LAST_UPDT_TS FROM SSD_MBL_DEV),
@LAST_UPDT_USEID = (SELECT LAST_UPDT_USEID FROM SSD_MBL_DEV)
EXEC ('INSERT INTO SSD.MBL_DEV VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
@DEV_NM, @MFG_NM, @MDL_NM, @OS_NM, @OS_VRSN, @SER_NBR, @DEV_TYPE_CODE, @DPLOY_STAT_CODE, @DPLOY_STAT_TS, @CTRY_CODE, @CO_CODE, @RT_NBR, @STRUC_NODE_SYS_NBR, @LAST_UPDT_TS, @LAST_UPDT_USEID) AT SSDDEV3
-- Reset loop variable
SELECT @NextDevice = NULL
SELECT @NextDevice = MIN(CAST(RIGHT(WS_ID,5) AS int))
FROM MCC_Import WHERE HH4 = 1 AND (WS_ID LIKE 'PEPCUH%' AND LEN(WS_ID) = 11)
AND WS_ID NOT IN (SELECT DEV_NM FROM OPENQUERY(SSDDEV3,'SELECT DEV_NM from SSD.MBL_DEV')) AND CAST(RIGHT(WS_ID,5) AS int) > CAST(RIGHT(@WS_ID,5) AS int)
IF ISNULL(@NextDevice,0) = 0
BEGIN
-- Done with all devices
BREAK
END
-- Set up next device
TRUNCATE TABLE SSD_MBL_DEV
SELECT @WS_ID = WS_ID FROM MCC_Import WHERE CAST(RIGHT(WS_ID,5) AS int) = @NextDevice END
-- Delete data from SSD_MBL_DEV table
TRUNCATE TABLE SSD_MBL_DEV
Tuesday, March 8, 2011 2:51 PM
Answers
-
> The OLE DB Provider for DB2 is only available for the Enterprise and Developer Editions of SQL Server 2005. I'm using Standard Edition. The DB2 OLE DB Provider is also not an option in Visual Studio 2005.
I checked this with my MVP mates, and apparently the DB2 provider only comes in the box with Enterprise. But if you acquire a license, there is no technical reason you could not use it with SSIS.
I'm not certain, but I believe that IBM also has a DB2 provider, and if you have DB2 in the house, you might already have a license.
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Links for SQL Server Books Online: SQL 2008, SQL 2005 and SQL 2000.
(Just click the link you need.)- Marked as answer by Ai-hua Qiu Wednesday, March 16, 2011 1:06 PM
Wednesday, March 9, 2011 10:31 PM
All replies
-
My main suggestion would be to use SSIS instead of trying to do this via a linked server. This should be able to handle the inserts a lot better
---
Shaun Turner
My Blog | My LinkedIn
If you're in the UK please join The SQL Developers / DBA's user group for the UK on LinkedInTuesday, March 8, 2011 4:08 PM -
It would have been nice to see the non-working insert. As far as I can see I would try populating the staging table ssd_mbl_dev first and using a single INSERT like
Your error message about the RPC normally indicates, that you need to activate RPC in the properties of the linked server. It also may be a driver problem see this thread .INSERT INTO SSD.MBL_DEV SELECT * FROM SSD_MBL_DEV ;
Microsoft MVP Office Access
https://mvp.support.microsoft.com/profile/Stefan.HoffmannTuesday, March 8, 2011 4:11 PM -
@Shaun -- not seeing the correct OLE DB provider in SSIS. Apparently a "feature" of SQL Server 2005 is the removal of the OLE DB Provider for ODBC, which is apparently what I need. It was restored in SQL Server 2008.
@Stefan -- when I try to run a more direct insert like the one you suggested, I get this:
Cannot execute the query "SELECT DEV_NM FROM SSD.MBL_DEV" against OLE DB provider "IBMDADB2.DB2COPY1" for linked server "SSDDEV3". The provider could not support an interface required for the UPDATE/DELETE/INSERT statements.The provider indicates that conflicts occurred with other properties or requirements.The provider could not support insertion on this table.The provider indicates that conflicts occurred with other properties or requirements.
Tuesday, March 8, 2011 7:30 PM -
@Shaun -- not seeing the correct OLE DB provider in SSIS. Apparently a "feature" of SQL Server 2005 is the removal of the OLE DB Provider for ODBC, which is apparently what I need. It was restored in SQL Server 2008.
@Stefan -- when I try to run a more direct insert like the one you suggested, I get this:
Cannot execute the query "SELECT DEV_NM FROM SSD.MBL_DEV" against OLE DB provider "IBMDADB2.DB2COPY1" for linked server "SSDDEV3". The provider could not support an interface required for the UPDATE/DELETE/INSERT statements.The provider indicates that conflicts occurred with other properties or requirements.The provider could not support insertion on this table.The provider indicates that conflicts occurred with other properties or requirements.
Still think SSIS is the best solution, had a quick dig on the forums, found this link:
Hopefully this helps
---
Shaun Turner
My Blog | My LinkedIn
If you're in the UK please join The SQL Developers / DBA's user group for the UK on LinkedInTuesday, March 8, 2011 8:00 PM -
Yeah, that's actually pretty similar in principle to what we were doing when we were on SQL Server 2000 -- exporting from the staging table to a .txt file and then using a DB2 script to upload it. I thought having a linked server would be a better solution but it hasn't worked out that way. I'm in contact with the DB2 team to see if we can revive the old system, which I know works.
Tuesday, March 8, 2011 9:09 PM -
> "Server '[Server Name]' is not configured for RPC." Our DB2 DBAs are telling me that this is a Microsoft issue and that there isn't anything they can do at their end to correct it. Any suggestions? Here is the SQL:
Indeed it is. Look up sp_serveroption in Books Online to set this option. (There are two of them. Set both. One is a no-op as I understand.)
But you will probably run into more problems - linked servers often mean hassle. SSIS might be better. There is no reason to use OLE DB over ODBC; there is a OLE DB provider for DB2.
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Links for SQL Server Books Online: SQL 2008, SQL 2005 and SQL 2000.
(Just click the link you need.)Tuesday, March 8, 2011 9:59 PM -
The OLE DB Provider for DB2 is only available for the Enterprise and Developer Editions of SQL Server 2005. I'm using Standard Edition. The DB2 OLE DB Provider is also not an option in Visual Studio 2005.Wednesday, March 9, 2011 2:38 PM
-
1st, to do bulk (fast) uploads to DB2 from SQL, you need our v3 version of the Microsoft OLE DB Provider for DB2, which was released with SQL Server 2008 R2 Feature Pack. You will also need the latest hotfix package. This will enable fastload to DB2. Fastload is only available with SSIS also. And, if you can justify it, you 'might' be able to get this provider for standard edition (you would need to open a case with support). Or you can optionally purchase a license for HIS 2010. If you have specific questions regarding the data provider, please ask your questions on the HIS forum - http://social.technet.microsoft.com/Forums/en-US/biztalkhis
Charles Ezzell - MSFT- Edited by Charles Ezzell Wednesday, March 9, 2011 4:59 PM edited answer
Wednesday, March 9, 2011 4:54 PM -
Sounds like I'll need to wait until we upgrade to SQL Server 2008 in order to get this working using SSIS. I don't administer the SQL Servers and we are in a shared environment, so I wouldn't be able to make these kinds of changes at the server level. I appreciate the info though.
For now I will focus on reactivating our previous system, which was to export the data to a .txt file and use a DB2 script to upload it.
Wednesday, March 9, 2011 7:30 PM -
The V3 provider is supported on SQL 2005 if that helps. What version/platform of DB2 are you using?
Charles Ezzell - MSFT- Proposed as answer by Charles Ezzell Wednesday, March 16, 2011 1:23 PM
Wednesday, March 9, 2011 9:53 PM -
> The OLE DB Provider for DB2 is only available for the Enterprise and Developer Editions of SQL Server 2005. I'm using Standard Edition. The DB2 OLE DB Provider is also not an option in Visual Studio 2005.
I checked this with my MVP mates, and apparently the DB2 provider only comes in the box with Enterprise. But if you acquire a license, there is no technical reason you could not use it with SSIS.
I'm not certain, but I believe that IBM also has a DB2 provider, and if you have DB2 in the house, you might already have a license.
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Links for SQL Server Books Online: SQL 2008, SQL 2005 and SQL 2000.
(Just click the link you need.)- Marked as answer by Ai-hua Qiu Wednesday, March 16, 2011 1:06 PM
Wednesday, March 9, 2011 10:31 PM