Connection Close 方法、Table Type 屬性範例 (VB)
將 ActiveConnection 屬性設定為 Nothing 應該會關閉目錄的連線。 相關聯的集合將會是空白。 從目錄中結構描述物件所建立的任何物件都會遭到孤立。 尚未快取物件上的任何屬性將仍然可用,但嘗試讀取需要呼叫提供者的屬性將會失敗。
' 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
關閉用於開啟目錄的 Connection 物件,應與將 ActiveConnection 屬性設定為 Nothing 的效果相同。
Attribute VB_Name = "Connection"
另請參閱
ActiveConnection 屬性 (ADOX)
Catalog 物件 (ADOX)
Column 物件 (ADOX)
Columns 集合 (ADOX)
Table 物件 (ADOX)
Tables 集合 (ADOX)
Type 屬性 (Table) (ADOX)
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應