| << 13.2.1- What is a Source? | Chapter13 | 13.2.3- What is the Cursor Type? >> |
What is the Active Connection?
The active connection identifies the data store connection. In the Recordset.asp example above, we used a connection string to specify the connection we wanted:
objRS.Open "Movies", strConnect, adOpenForwardOnly, adLockReadOnly, adCmdTable
Instead, you could use a Connection object, like we did in the Connect.asp example in Chapter 12 :
objConn.Open strConnect
objRS.Open "Movies", objConn, adOpenForwardOnly, adLockReadOnly, adCmdTable
We discussed this earlier in the chapter. Essentially, you'd use the first technique if you're only making a single query to the data store – because it saves us from creating an explicit Connection object in our code, and keeps the code more tidy.
By contrast, you'd use the second technique if you were making a number of queries to the same data store. You can create the connection once using the Connection object, and then use the open connection each time you need it:
objConn.Open strConnect
objRSTitles.Open "SELECT Title FROM Movies", objConn
objRSLinks.Open "SELECT * FROM MovieLinks", objConn
...
That's a useful technique, because creating a connection is a resource-expensive task.
The ActiveConnection Property
Alternatively, you can set the ActiveConnection using the Recordset object's ActiveConnection property. For example:
objRS.ActiveConnection = strConnect
or
Set objRS.ActiveConnection = objConn
Although the two lines above appear to achieve the same thing, we get the same subtle difference. In the first, a connection string is passed in, and this causes a new connection to be created. In the second, the existing Connection object (objConn) is used as the connection.
| << 13.2.1- What is a Source? | Chapter13 | 13.2.3- What is the Cursor Type? >> |

RSS

