请教数据库编程高手

Fortune

新手上路
注册
2003-01-31
消息
105
荣誉分数
0
声望点数
0
如何将 多数据源(例如:MS SQL Server 和 MS Access)绑定到一个Recordset中去。 这样我可以用一条SQL语句对2个数据库进行查询。
谢谢回复!
 
好象是不可能的~。你用什么工具?
 
我现在用VC++. 如果能实现用什么工具都可以。
 
我知道用一般的编程方法肯定是不行的...但肯定有特别方法可以解决的。
 
我能想到的办法就是通过两个连接分别执行两个SQL,然后将得到的结果集通过C++代码合并为一个结果集。想不出如何通过一个连接访问不同的数据源。
 
嘻嘻,找到答案了

Distributed Query Processor

The Distributed Query Processor (DQP) feature of Microsoft SQL Server 7.0 enables application developers to develop heterogeneous queries that join tables in disparate databases. To access the remote data sources, a user must create a Linked Server definition. The Linked Server encapsulates all of the network, security, and data source-specific information required to connect DQP to the remote data. Linked servers rely on underlying OLE DB providers or ODBC drivers for the actual physical connection to the target data source. Once a linked server has been defined, it can always be referred to with a single logical name as part of a SQL Server dynamic SQL statement or stored procedure. At run time, a linked server resource, such as a remote DB2 table, is treated like a local SQL Server table.

When a client application executes a distributed query using a linked server, SQL Server analyzes the command and sends any requests for linked server data via OLE DB to that data source. If security credentials were specified when the linked server was created, those credentials are passed to the linked server. Otherwise, SQL Server will pass the credentials of the current SQL Server login. When SQL Server receives the returned data, it is processed in conjunction with other portions of the query.

DQP can concurrently access multiple heterogeneous sources on local and remote computers. Additionally, it supports queries against both relational and nonrelational data by using OLE DB interfaces implemented in OLE DB providers. Using DQP, SQL Server administrators and end user developers can create linked server queries that run against multiple data sources with little or no modifications required. For example, a Visual Basic developer can create a single linked server query that selects and inserts data stored in DB2 today, and then can change the linked server name and run the same query against Microsoft SQL Server tomorrow. In this way, DQP provides the developer with an isolation level against changes in the storage engine.

Further, DQP is an efficient tool with which to join information from multiple tables spanning multiple data sources. For example, let’s say you are a regional sales manager for a large retail company with subsidiaries located in several countries. Because of mergers and acquisitions, some regional offices store their data in different databases from those of the corporate headquarters. The United Kingdom subsidiary stores its data in DB2; the Australian subsidiary stores its data in Microsoft Access; the Spanish subsidiary stores its data in Microsoft Excel; and the United States subsidiary stores its data in Microsoft SQL Server. You want a report that lists, on a quarterly basis for the last three years, the subsidiaries and the sales locations with the highest quarterly sales figures. Joining the required data tables can be accomplished in real time by using a single distributed query, running on Microsoft SQL Server.

For additional information, see "Creating a Heterogeneous Query with Microsoft SQL Server 7.0."
 
Re: 我的看法

ADO.ENT 中的Dataset 对象, 可以组合不同数据来源的表格, 例如来自于文本, xml, 各种数据库, 但是不支持SQL, 这也是OO的尴尬, 遇到大量数据处理, 就必须依靠结构化的SQL.
有一个简单Dataview, 可以对表格作简单的筛选和排序.
 
哈哈,dpff的方法解决我的难题了!!!
多多感谢以上几位朋友。
 
后退
顶部