Recently I used ASP. NET to create an MDB file. After I found that the MDB file was created using ADOX. CATALOG, a temporary LDB log file will be generated;
The MDB file with LDB is in the "open" status, and it is difficult to perform operations such as "delete.
After searching for problems and summarizing methods on the Internet, we found that we still need to implement the IDISPOSABLE interface on the class to implement temporary hosting.
1. First, we will introduce "What are managed resources and unmanaged resources ":
(1) managed resources: Resources allocated and released by CLR management, typically managed memory, rather than allocated and released by the system; generally, you do not need to manually release the memory for a new object in the CLR or allocate an array. The memory occupied by the new object is the managed resource.
Unmanaged resources: All Window kernel objects (handles) are unmanaged resources, such as file handles, socket handles, form handles, fonts, brushes, and DC...
(2) supplement:
It should be said that the word "hosting" is and. net concept, we all know that the previous development tools, whether it is Delphi, VB compiled dll or exe files are binary files, can be directly recognized by the operating system. Microsoft has proposed to work hard with JAVA to achieve cross-platform purposes. net concept, the general principle is not to mention (there are books), simply put, is to propose a set of intermediate language (IL), and then let the program compile to generate intermediate language files, then translate and manage through our own CLR, so we can say that CLR is "hosted". Just kidding, no matter who cares about it. "Unmanaged" means the CLR cannot manage it.
2. The method for releasing the LDB file is as follows (create a class for implementation ):
'This class is used to generate MDB files
Public Class DisposeExample
Public Class Create_MDB
Implements IDisposable (after the IDISPOSABLE interface is declared, the following code is automatically generated)
Dim cat As ADOX. Catalog = New ADOX. Catalog
Private disposedValue As Boolean = false' checks redundant calls
Public Sub Create_MDB_Function (ByVal path As String)
Cat. Create (path)
End Sub
'Idisposable
Protected Overridable Sub Dispose (ByVal disposing As Boolean)
If Not Me. disposedValue Then
If disposing Then
'Todo: Release managed resources when explicitly calling
'Release the temporary LDB File
Cat = Nothing
System. GC. Collect ()
End If
'Todo: Release shared unmanaged Resources
End If
Me. disposedValue = True
End Sub
Finally, you only need to call this class where the function is implemented.