Sun Chili!Soft ASP Sun Chili!Soft
ASP Sun Microsystems

 

ADO Recordset Object ActiveConnection Property

Specifies to which Connection object the Recordset object currently belongs.

ActiveConnection Property Return Values (ADO Recordset Object)

Sets or returns a String containing the definition for a connection or an ADO Connection Object. Default is a Null object reference.

ActiveConnection Property Remarks (ADO Recordset Object)

Use the ActiveConnection property to determine the Connection object over which the specified Command object will execute or the specified recordset will be opened.

For open Recordset objects or for Recordset objects whose ADO Recordset Object Source Property is set to a valid ADO Command Object, the ActiveConnection property is read-only. Otherwise, it is read/write.

You can set this property to a valid Connection object or to a valid connection string. In this case, the provider creates a new Connection object using this definition and opens the connection. Additionally, the provider may set this property to the new Connection object to give you a way to access the Connection object for extended error information or to execute other commands.

If you use the ActiveConnection argument of the ADO Recordset Object Open Method to open a Recordset object, the ActiveConnection property will inherit the value of the argument.

If you set the Source property of the Recordset object to a valid Command object variable, the ActiveConnection property of the recordset inherits the setting of the Command object's ActiveConnection property.

ActiveConnection Property Example (ADO Recordset Object)

This Visual Basic example uses the ActiveConnection, ADO Command Object CommandText Property, CommandTimeout, ADO Command Object CommandType Property, ADO Parameter Object Size Property, and ADO Parameter Object Direction Property properties to execute a stored procedure:

Public Sub ActiveConnectionX()

Dim cnn1 As ADODB.Connection

Dim cmdByRoyalty As ADODB.Command

Dim prmByRoyalty As ADODB.Parameter

Dim rstByRoyalty As ADODB.Recordset

Dim rstAuthors As ADODB.Recordset

Dim intRoyalty As Integer

Dim strAuthorID As String

Dim strCnn As String

` Define a command object for a stored procedure.

Set cnn1 = New ADODB.Connection

strCnn = "driver={SQL Server};server=srv;" & _

"uid=sa;pwd=;database=pubs"

cnn1.Open strCnn

Set cmdByRoyalty = New ADODB.Command

Set cmdByRoyalty.ActiveConnection = cnn1

cmdByRoyalty.CommandText = "byroyalty"

cmdByRoyalty.CommandType = adCmdStoredProc

cmdByRoyalty.CommandTimeout = 15

` Define the stored procedure's input parameter.

intRoyalty = Trim(InputBox( _

"Enter royalty:"))

Set prmByRoyalty = New ADODB.Parameter

prmByRoyalty.Type = adInteger

prmByRoyalty.Size = 3

prmByRoyalty.Direction = adParamInput

prmByRoyalty.Value = intRoyalty

cmdByRoyalty.Parameters.Append prmByRoyalty

` Create a recordset by executing the command.

Set rstByRoyalty = cmdByRoyalty.Execute()

` Open the Authors table to get author names for display.

Set rstAuthors = New ADODB.Recordset

rstAuthors.Open "authors", strCnn, , , adCmdTable

` Print current data in the recordset, adding

` author names from Authors table.

Debug.Print "Authors with " & intRoyalty & _

" percent royalty"

Do While Not rstByRoyalty.EOF

strAuthorID = rstByRoyalty!au_id

Debug.Print , rstByRoyalty!au_id & ", ";

rstAuthors.Filter = "au_id = '" & strAuthorID & "'"

Debug.Print rstAuthors!au_fname & " " & _

rstAuthors!au_lname

rstByRoyalty.MoveNext

Loop

rstByRoyalty.Close

rstAuthors.Close

cnn1.Close

End Sub

Copyright 2002 Sun Microsystems, Inc. All rights reserved. Legal Notice.