Esempio del metodo Close di Connection e della proprietà Type di Table (VB)

L'impostazione della proprietà ActiveConnection su Nothing deve chiudere la connessione al catalogo. Le raccolte associate saranno vuote. Tutti gli oggetti creati da oggetti schema nel catalogo saranno orfani. Tutte le proprietà di tali oggetti memorizzati nella cache saranno comunque disponibili, ma un tentativo di lettura delle proprietà che richiede una chiamata al provider avrà esito negativo.

' BeginCloseConnectionVB  
Sub Main()  
    On Error GoTo CloseConnectionByNothingError  
  
    Dim cnn As New ADODB.Connection  
    Dim cat As New ADOX.Catalog  
    Dim tbl As ADOX.Table  
  
    cnn.Open "Provider='Microsoft.Jet.OLEDB.4.0';" & _  
        "Data Source= 'Northwind.mdb';"  
    Set cat.ActiveConnection = cnn  
    Set tbl = cat.Tables(0)  
    Debug.Print tbl.Type    ' Cache tbl.Type info  
    Set cat.ActiveConnection = Nothing  
    Debug.Print tbl.Type    ' tbl is orphaned  
    ' Previous line will succeed if this info was cached.  
    Debug.Print tbl.Columns(0).DefinedSize  
    ' Previous line will fail if this info has not been cached.  
  
    'Clean up.  
    cnn.Close  
    Set cat = Nothing  
    Set cnn = Nothing  
    Exit Sub  
  
CloseConnectionByNothingError:  
    Set cat = Nothing  
  
    If Not cnn Is Nothing Then  
        If cnn.State = adStateOpen Then cnn.Close  
    End If  
    Set cnn = Nothing  
  
    If Err <> 0 Then  
        MsgBox Err.Source & "-->" & Err.Description, , "Error"  
    End If  
End Sub  
' EndCloseConnectionVB  

La chiusura di un oggetto Connection utilizzato per aprire il catalogo deve avere lo stesso effetto dell'impostazione della proprietà ActiveConnection su Nothing.

Attribute VB_Name = "Connection"  

Vedere anche

Proprietà ActiveConnection (ADOX)
Oggetto Catalog (ADOX)
Oggetto Column (ADOX)
Raccolta Columns (ADOX)
Oggetto Table (ADOX)
Raccolta Tables (ADOX)
Proprietà Type (Table) (ADOX)