Microsoft KB Archive/300878

From BetaArchive Wiki

HOW TO: Pass ADO Recordset Information to COM Object in ASP

Q300878



SUMMARY

This step-by-step procedure demonstrates how to create an ActiveX Data Objects (ADO) Recordset object from the NorthWind sample database and pass that information to a Component Object Model (COM) object. This example creates a hypothetical COM object called Employee and passes information from the Employees table in the NorthWind database to the object. The hypothetical component accepts the employee information to perform calculations for an unspecified application.

[GRAPHIC: Step 1] Select a Record

First, you must select a specific record to use. Follow these steps to create the first Active Server Pages (ASP) page (Adocom1.asp), which contains a drop-down list box that is populated with names from the Employees table.

  1. From the Start menu, point to Programs, point to Accessories, and then click Notepad.
  2. In Notepad, create a new ASP page named Adocom1.asp, and paste the following code:
  3. Save Adocom1.asp in the root directory of your Web server. (for example, C:\InetPub\Wwwroot\Aspcom1.asp).

[GRAPHIC: Step 2] Pass the Recordset to a COM Object

Follow these steps to create the second ASP page (Adocom2.asp) to take the specific record that is passed from the first page, assign the information to variables, and pass this to the COM object.

  1. In Notepad, create a new ASP page named Adocom2.asp, and paste the following code:
  2. Save Adocom2.asp in the root directory of your Web server (for example, C:\InetPub\Wwwroot\Aspcom2.asp).

[GRAPHIC: Step 3] Run the Application

To run this application, follow these steps:

  1. In your Web browser, type http://<servername>/adocom1.asp in the Address bar, and press ENTER.
  2. Select a name from the drop-down list box, and then click Submit.

NOTE: Because we are not using a real COM object, that portion of the code does not work.

[GRAPHIC: Step 4] Pitfalls

When you use ActiveX Data Objects (ADO) in ASP, make sure that you:

  • Always close recordsets and connections. For example:
  • Open late, and close early. Open ADO objects just before they are needed, and close them right after you are done. This frees resources while other logic is processing.
  • Do not create ADO objects in session variables. This effectively bypasses MTX connection and thread pooling, which is detrimental. If threads are not pooled, each object that a user creates can tie up a thread. To worsen the situation, if the object is not specifically closed, a session object variable can live and tie up a thread for the lifetime of a session (20 minutes after the last click).
  • Do not pass parameters to the Command object in the execute statement.
  • Instantiate objects with the Server.CreateObject method if you are not marshaling data through a firewall. Server tells Microsoft Transaction Server (MTS) to create the object in a transaction server package so that resources are pooled.


NOTE: This does not apply to Microsoft Internet Information Services (IIS) 5.0 or Microsoft COM+.

  • Do not re-use Recordset or Command variables; create new ones.

[GRAPHIC: Step 5] REFERENCES

For more information, see the following Microsoft Web sites:

Dr. GUI's Gentle Guide to COM

http://www.microsoft.com/Com/news/drgui.asp

Microsoft Windows Scripting Technologies
http://msdn.microsoft.com/scripting/

MSDN Library - ActiveX Data Objects (ADO)

http://msdn.microsoft.com/library/psdk/dasdk/ados4piv.htm

Additional query words:

Keywords : _IK kbGraphxLink kbAudDeveloper kbHOWTOmaster
Issue type : kbhowto
Technology :


Last Reviewed: June 15, 2001
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.