HELP - Closing all open objects

Results 1 to 2 of 2

Thread: HELP - Closing all open objects

  1. #1
    Ed Guest

    Default HELP - Closing all open objects

    Can you reference (from ASP) a collection of all open objects? I&#039d like to be able to close all open connection and recordset objects without knowing their names. For example:<BR><BR>Set colOpenItems = [This is what I need to know]<BR><BR>For Each varItem In colOpenItems<BR> varItem.Close<BR> Set varItem = Nothing<BR>Next<BR><BR>Thanks!<BR><BR><BR><BR><BR> <BR>

  2. #2
    Join Date
    Dec 1969

    Default Closing all open objects--two ways

    There&#039s a "secret" answer and a mundane answer. Ready?<BR><BR>The secret answer is:<BR><BR> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#060;/HTML&#062;<BR><BR>In other words, leave the ASP page. Quit. Be done.<BR><BR>The rules of ASP and ActiveX require that all open objects be closed and collected whenever an ASP page completes.<BR><BR>In the past, people reported bugs in the process. But I haven&#039t heard of any in over a year. And I guarantee that, as sloppy as most ASP programmers are, *MILLIONS* of connections and recordsets and who knows whats are being left open every day. If doing that caused system disasters, how come we don&#039t here about it in every other post on every ASP message board?<BR><BR>ANYWAY...ANSWER #2: <BR><BR>The answer to your real question: There&#039s no way. There *could* be a way. After all, the ASP engine, under the covers, has to find and close and nullify all those objects. So an API could be provided to you so you could do it. But as of this date such an API doesn&#039t exist.<BR><BR>If this matters to you, then consider constructing your own "class factory", thus:<BR><BR>&#060;%<BR>Dim openObjects( 1000 ) &#039 that&#039s only 16K bytes...who cares?<BR>Dim openObjCount <BR>openObjCount = -1<BR><BR>Function ObjectCreate( what )<BR> &nbsp; Dim temp<BR> &nbsp; Set temp = Server.CreateObject( what )<BR> &nbsp; openObjCount = openObjCount + 1<BR> &nbsp; Set openObjects( openObjCount ) = temp<BR> &nbsp; Set ObjectCreate = temp<BR>End Function<BR><BR>Sub CloseAll( )<BR> &nbsp; For onum = 0 To openObjCount<BR> &nbsp; &nbsp; &#039 ignore errors on close<BR> &nbsp; &nbsp; On Error Resume Next<BR> &nbsp; &nbsp; openObjects(onum).Close &#039 try to close the object<BR> &nbsp; &nbsp; On Error Goto 0<BR> &nbsp; Next<BR>End Sub<BR>%&#062;<BR><BR>So now, instead of calling Server.CreateObject to create these objects you want to be sure are closed, you call your own ObjectCreate function.<BR><BR>Simple?<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts