Umgang mit ADODB-connections-in classic ASP

Ich bin ein ASP.NET C# - Typ, der zurück zum klassischen ASP, und brauche etwas Hilfe.

Ersten, Blick auf diese beiden Funktionen (ich weiß, in VBScript, sind die Kommentare erklärt ' und nicht durch // aber der syntax-highlighter hier vermasselt mit ').

Erste version:

Function DoThing

    Dim Connection, Command, Recordset

    Set Connection = Server.CreateObject("ADODB.Connection")
    Set Command = Server.CreateObject("ADODB.Command")
    Set Recordset = Server.CreateObject("ADODB.Recordset")

    Connection.Open "blah blah blah"
    Command.CommandText = "blah blah blah"
    Recordset.Open Command, Connection

    If Recordset.EOF = False Then

        While Recordset.EOF = False Then

            // Do stuff.

            Recordset.MoveNext

        WEnd

    Else

        // Handle error.

    End If

    Recordset.Close
    Connection.Close

    Set Recordset = Nothing
    Set Command = Nothing
    Set Connection = Nothing

End Function

Zweite version:

Function DoAnotherThing

    Dim Connection, Command, Recordset

    Set Connection = Server.CreateObject("ADODB.Connection")
    Set Command = Server.CreateObject("ADODB.Command")

    Connection.Open "blah blah blah"

    Command.ActiveConnection = Connection
    Command.CommandText = "blah blah blah"

    Set Recordset = Command.Execute

    If Recordset.EOF = False Then

        While Recordset.EOF = False Then

            // Do stuff.

            Recordset.MoveNext

        WEnd

    Else

        // Handle error.

    End If

    Recordset.Close
    Connection.Close

    Set Recordset = Nothing
    Set Command = Nothing
    Set Connection = Nothing

End Function

Nun, beginnen wir mit den Fragen:

Frage #1:

Was das beste ist,

Connection.Open "blah blah blah"
Command.CommandText = "blah blah blah"
Recordset.Open Command, Connection

oder

Connection.Open "blah blah blah"

Command.ActiveConnection = Connection
Command.CommandText = "blah blah blah"

Set Recordset = Command.Execute

?

Frage #2:

Wenn dabei Wählt sollte ich disconnected recordsets wie

Set Recordset = Command.Execute

Command.ActiveConnection = Nothing

Connection.Close

Set Connection = Nothing

?

Frage #3:

Muss ich anrufen

Recordset.Close
Connection.Close

obwohl ich

Set Recordset = Nothing
Set Command = Nothing
Set Connection = Nothing

rechts unten (d.h. der garbage collector aufgerufen, wenn von der Set Stuff= Nothing auch .Close Sie vor der Zerstörung)?

Frage #4:

Muss ich gehören die

Recordset.Close
Connection.Close

Set Recordset = Nothing
Set Command = Nothing
Set Connection = Nothing

Zeug, obwohl die Funktion dort endet, und diese Objekte außerhalb des Gültigkeitsbereichs und der garbage collector (sollten) kümmert sich um Sie?

Frage #5:

Tun, classic ASP zusammengefasste Verbindung, so kann ich Sie öffnen und schließen Sie mit jedem Befehl, oder sollte ich passiere ein gemeinsames connection-Objekt um?

 

Vielen Dank im Voraus für Eure Hilfe, Andrea.

Für vernünftige VB-Kommentare auf StackOverflow, hinzufügen schließende einfache Anführungszeichen, die am Ende jedes Kommentars. Ansonsten der code-Formatierer, Sie sind nur nicht-Zeichenfolgen.

InformationsquelleAutor Albireo | 2010-09-22

Schreibe einen Kommentar