Re: What is a good strategy for joining data from separate databases

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance





"Eric" <someone@xxxxxxxxxx> wrote in message news:#$dGffoDHHA.3660@xxxxxxxxxxxxxxxxxxxxxxx

I have a situation where I must restructure my data access, and was hoping the community could give me pointers or links to articles that would help.

My situation is that I need to query data from two separate databases. One is my application's own database, and the other is a Data Mart created for me with a view I access. The way I do it currently requires that the SQL-Servers be linked, and, given our security setup, on the same SQL-Server.

Currently the cross database queries take two forms:

SELECT field FROM MyAppDataMart..vwAppData vw
JOIN MyOwnDatabaseTable tbl ON vw.Field = tbl.Field
OR
SELECT field FROM MyAppDataMart..vwAppData vw
WHERE NOT EXISTS(SELECT field FROM MyOwnDatabaseTable tbl WHERE vw.Field = tbl.Field)


My current .NET business object merely makes a single stored procedure call to retrieve a resultset, with any joins required handled by the stored procedure. It is now considered unacceptable to have a dependency like that in the stored procedure and I need to re-structure the data access such that the .NET business object retrieves data separately from each database eliminiating the need for one database to be able to be linked or even aware of the other.


What you have is a reasonable strategy, and I would push back on the notion that it's "unacceptable". Your alternatives are not really better.

This means, however, that I must handle any JOIN or EXISTS logic in my business object, and I am looking for strategies to accomplish that. From what I have read so far, I'm not sure the DataRelation in ADO.NET can enforce logic more complex than a INNER JOIN.

In short, what I need to go to is from

Existing:
-Call stored procedure which bridges Database1 and Database2 and returns a resultset.
Desired:
-Retrieve info from Database1
-Retrieve info from Database2
-Apply any logic such as JOIN or EXISTS or NOT EXISTS to filter data
-Return resultset.


I think these are your options:

1) "JOIN" in client code.
Slow, expensive an requires a lot of code: avoid if at all possible.

2) Replicate data into your local database.
Possible, depending on the latency, size etc. Requires setup and monitoring on the server.

3) Construct the SQL for a cross-database JOIN in client code
Basically the same as your current solution, except the dependency is removed from the stored procedure.

David

.



Relevant Pages

  • Re: Extended Stored Procedure: Get the current db of the client
    ... with the caveat that you don't recommend it because Microsoft ... of a stored procedure versus umpteen of the same stored procedure spread ... I am not going after Gert Sue. ... the database context as a parameter if you need it, ...
    (microsoft.public.sqlserver.odbc)
  • Trying to set up a SQL Server Agent Account and I hit a wall....
    ... Our database is on SQL Server 2005, however it is set to compatibility mode ... You may need to set the compatibility level ... of the current database to a higher value to enable this feature. ... for the stored procedure sp_dbcmptlevel. ...
    (microsoft.public.sqlserver.security)
  • Re: Unbound Data Access
    ... Instead of attempting this in client code, ... creating a stored procedure to handle the problem? ... the sproc, which performs the computations and inserts the data into ... database or on the same server. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Extended Stored Procedure: Get the current db of the client
    ... I am not going after Gert Sue. ... the database context as a parameter if you need it, ... Did you ever write an extended stored procedure? ... different than an extended stored procedure, so that is not giving you want ...
    (microsoft.public.sqlserver.odbc)
  • Re: Extended Stored Procedure: Get the current db of the client
    ... Thanks for the link Sue. ... I am not going after Gert Sue. ... the database context as a parameter if you need it, ... Did you ever write an extended stored procedure? ...
    (microsoft.public.sqlserver.odbc)