Compartir a través de


Ejemplo de propiedad Type de tabla, método connection close (VB)

Establecer la propiedad ActiveConnection enNothing debe cerrar la conexión al catálogo. Las colecciones asociadas estarán vacías. Los objetos creados a partir de objetos de esquema en el catálogo estarán huérfanos. Las propiedades de esos objetos que se han almacenado en caché seguirán estando disponibles, pero se producirá un error al intentar leer las propiedades que requieren una llamada al proveedor.

' 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  

Cerrar un objeto Connection que se usó para abrir el catálogo debe tener el mismo efecto que establecer la propiedad ActiveConnection en Nothing.

Attribute VB_Name = "Connection"  

Consulte también

ActiveConnection (propiedad, ADOX)
Objeto Catalog (ADOX)
Objeto Column (ADOX)
Colección de columnas (ADOX)
Objeto Table (ADOX)
Colección de tablas (ADOX)
Type (propiedad, tabla, ADOX)