PDA

View Full Version : فشرده کردن data base



mohamad6
دوشنبه 20 مرداد 1382, 10:08 صبح
با سلام
طریقه فشرده کردن بانک اطلاعاتی اکسس از طریق کد نویسی چگونه است؟(با مدل ado)

A.Noor
سه شنبه 04 شهریور 1382, 10:45 صبح
این کد را امتحان کنید . نمی‌دانم درست کار می‌کند یا نه

'************************************************* **************
' CompactAndRepairDB (FUNCTION)
'
' PARAMETERS:
' sSource - Path to source database
' sDestination - Path for destination database
' sSecurity - Path to Jet system database if there is
' one
' sUser - The username if user level security is
' turned on
' sPassword - The password if user level security is
' turned on
' lDestinationVersion - If the destination database should
' not be in the latest version of Jet
' then use this variable to specify
' the version required; 1 = Jet 1.0,
' 2 = Jet 1.1, 3 = Jet 2.x,
' 4 = Jet 3.x, 5 = Jet 4.x etc
'
' RETURN VALUE:
' Boolean - Success indicator
'
' DESCRIPTION:
' This function uses the Microsoft Jet and Replication Objects
' Library (part of ADO) to compact and repair a Microsoft Access
' database. A project reference is required to the Microsoft Jet
' and Replication Objects Library.
'
' You may want to add error handling to this procedure, or to
' the function that calls it as the compact and repair may fail,
' for instance, if exclusive access cannot be gained to the
' source database.
'************************************************* **************
Public Function CompactAndRepairDB(sSource As String, _
sDestination As String, _
Optional sSecurity As String, _
Optional sUser As String = "Admin", _
Optional sPassword As String, _
Optional lDestinationVersion As Long) As Boolean

Dim sCompactPart1 As String
Dim sCompactPart2 As String
Dim oJet As JRO.JetEngine

' Put together the provider string for the source database
sCompactPart1 = "Provider=Microsoft.Jet.OLEDB.4.0" & _
";Data Source=" & sSource & _
";User Id=" & sUser & _
";Password=" & sPassword

' If the database has a user-level security file, add the
' details
If sSecurity <> "" Then
sCompactPart1 = sCompactPart1 & _
";Jet OLEDB:System database=" & sSecurity & ";"
End If

' Put together the provider string for the destination
' database
sCompactPart2 = "Provider=Microsoft.Jet.OLEDB.4.0" & _
";Data Source=" & sDestination

' The destination database will end up in the latest version
' of jet, unless a specific version has been requested;
' 1 = Jet 1.0, 2 = Jet 1.1, 3 = Jet 2.x, 4 = Jet 3.x,
' 5 = Jet 4.x etc
If lDestinationVersion <> 0 Then
sCompactPart2 = sCompactPart2 & _
";Jet OLEDB:Engine Type=" & lDestinationVersion
End If

' Compact and repair the database
Set oJet = New JRO.JetEngine
oJet.CompactDatabase sCompactPart1, sCompactPart2
Set oJet = Nothing

CompactAndRepairDB = True
End Function