此頁沒有內(nèi)容條目
內(nèi)容

   

指示指定的 CommandRecordset 對象當前所屬的 Connection 對象。

設置和返回值

設置或返回包含了定義連接或 Connection 對象的字符串。默認情況下為 Null 對象引用。

說明

使用 ActiveConnection 屬性可確定在其上將執(zhí)行指定 Command 對象或打開指定 RecordsetConnection 對象。

命令

對于 Command 對象,ActiveConnection 屬性為讀/寫。

在將該屬性設置為打開的 Connection 對象或有效連接字符串之前,試圖調(diào)用 Command 對象的 Execute 方法將產(chǎn)生錯誤。

Microsoft Visual Basic   將 ActiveConnection 屬性設置為 Nothing 可使 Command 對象與當前 Connection 脫離關聯(lián),并使提供者釋放數(shù)據(jù)源上所有關聯(lián)的資源。然后,可以使 Command 對象與相同的 Connection 對象或其他 Connection 對象關聯(lián)。某些提供者允許將該屬性設置從一個 Connection 更改到另一個 Connection,而不必首先將該屬性設置為 Nothing。

如果 Command 對象的 Parameter 集合包含提供者提供的參數(shù),那么假如將 ActiveConnection 屬性設置為 Nothing 或設置為其他 Connection 對象,將清除集合。如果手工創(chuàng)建 Parameter 對象并使用這些參數(shù)填充 Command 對象的 Parameters 集合,則將 ActiveConnection 屬性設置為 Nothing 或其他 Connection 對象不會影響 Parameters 集合。

關閉與 Command 對象相關聯(lián)的 Connection 對象將把 ActiveConnection 屬性設置為 Nothing。將該屬性設置為已關閉的 Connection 對象將產(chǎn)生錯誤。

Recordset

對于打開的 Recordset 對象或其 Source 屬性被設置為有效 Command 對象的 Recordset 對象,ActiveConnection 屬性為只讀。否則,該屬性為讀/寫。

可以將該屬性設置為有效的 Connection 對象,或設置為有效的連接字符串。這時,提供者可使用該定義創(chuàng)建新的 Connection 對象,并打開連接。另外,提供者可以將該屬性設置為新的 Connection 對象,以便向您提供訪問擴展錯誤信息的 Connection 對象或執(zhí)行其他命令。

如果使用 Open 方法的 ActiveConnection 參數(shù)打開 Recordset 對象,ActiveConnection 屬性將繼承該參數(shù)的值。

如果將 Recordset 對象的 Source 屬性設置為有效 Command 對象變量,Recordset ActiveConnection 屬性將繼承 Command 對象的 ActiveConnection 屬性的設置。

遠程數(shù)據(jù)服務用法   在客戶端 (ADOR) Recordset 對象上使用時,只能將該屬性設置為連接字符串或(Microsoft Visual Basic 或 VBScript 中)Nothing