简体   繁体   中英

Effectively join two tables from Oracle and SQL Server in C#

So I have two systems I often have to join together to display certain reports. I've got one system that stores metadata on documents that is stored in SQL Server, usually by part number. The list of part numbers I would want to get documents for come from an Oracle table in our ERP system. My current method goes like this:

  1. Get data from ERP (Oracle) system into a DataTable .
  2. Compile string[] of part numbers from a column.
  3. Use an IN() statement to get all document information from docs (MSSQLSVR) system into another DataTable .
  4. Add columns to ERP DataTable , loop through rows.
  5. Fill out document info from docs DataTable , if(erpRow["ITEMNO"] == docRow["ITEMNO"])

This, to me feels really inefficient. Now obviously I can't use one connection string to JOIN the two tables, or use a database link, so I assume there will have to be two calls, one to each database. Is there another way to join these two sets together?

I would suggest a LikedServer approach ( http://msdn.microsoft.com/en-us/library/ms188279.aspx ). Write a Stored Procedure on the SQL Server side that pulls the data over from an Oracle Linked Server, does the JOIN locally and returns the combined data.

SQL Server has been designed to execute JOINs efficiently. No need to try to recreate that functionality in the app layer.

Since you've ruled out a database link I would do the following

  1. Get data from ERP (Oracle) system into a DataTable.
  2. Pass DataTable as a Parameter to SQL Server via a Table-Valued Parameter
  3. Return your data (no loops updating an older set)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM