ADODB.recordset有2个数据库 [英] ADODB.recordset with 2 databases

查看:99
本文介绍了ADODB.recordset有2个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我们使用这样的ADODB.recordset在我们的单个数据库上运行UNION查询...


OpenDataConnection()

set rsID = CreateObject(" ADODB.recordset")

searchphrase =" SELECT t。*

" FROM table1 t"

" UNION

SELECT t。*

" FROM table2 t"

" ORDER BY Name"

rsID.open searchphrase,oConn

CloseDataConnection()


但是table1和table2已经变得如此之大他们需要被放置在他们自己的dbs中,所以现在我们将有2个dbs但仍然想要运行这个查询。


所以推测我现在打开2个连接

另外,我需要在searchPhrase中对表格前面的数据库名称进行限定

但是,当我打开记录集时,如何引用2打开的连接即。这里


rsID.open searchphrase,oConn


因为它只需要一个参数。


任何帮助都会很棒,提前谢谢。

解决方案

您好TimSki,


假设您有两个名为的数据库Database1和Database2在同一服务器上然后您只需要一个连接并且可以使用以下SQL查询:

展开 | 选择 | 换行 | 行号


< blockquote>非常感谢您的快速回复。也许是一个愚蠢的问题,但可能我仍然需要打开和关闭两个数据库连接?


没问题。


关键问题是两个数据库是否在同一个SQL Server上。如果是这样,那么您只需要打开和关闭一个连接。可以将连接视为SQL服务器与连接字符串中指定的默认数据库,而不是与数据库本身的连接。


试一试让我知道如何它去了。


B博士


Hi,

We have been running a UNION queriy on our single db using an ADODB.recordset like this...

OpenDataConnection()
set rsID = CreateObject("ADODB.recordset")
searchphrase = " SELECT t.*
" FROM table1 t "
" UNION "
" SELECT t.*
" FROM table2 t "
" ORDER BY Name "
rsID.open searchphrase, oConn
CloseDataConnection()

However table1 and table2 have grown so large they need to be placed in their own dbs, so now we will have 2 dbs but still want to run this query.

So presumambly i now open 2 connections
Also, i will need to qualify the db name in front of the table in the searchPhrase
BUT, how can a refer to the 2 open connection when i open the recordset ie. here

rsID.open searchphrase, oConn

as it only takes a single parameter.

Any help would be great, thanks in advance.

解决方案

Hi TimSki,

Assuming that you have two databases called Database1 and Database2 on the same server then you only need one connection and can use the following SQL query:

Expand|Select|Wrap|Line Numbers


thanks very much for the prompt reply. perhaps a stupid question but presumably i still need to open and close both database connections ?


No problem.

The crucial question is whether both databases are on the same SQL Server. If so then you only need to open and close one connection. Think of the connection as being to the SQL server with a default database specified in the connection string rather than being a connection to the database itself.

Give it a try and let me know how it goes.

Dr B


这篇关于ADODB.recordset有2个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆