-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathte_compactall.asp
More file actions
180 lines (159 loc) · 5.43 KB
/
te_compactall.asp
File metadata and controls
180 lines (159 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<%
'==============================================================
' TableEditoR 0.81 Beta
' http://www.2enetworx.com/dev/projects/tableeditor.asp
'--------------------------------------------------------------
' File: te_compactall.asp
' Description: Bulk Compact databases
' Initiated By ? on ?
'--------------------------------------------------------------
' Copyright (c) 2002, 2eNetWorX/dev.
'
' TableEditoR is distributed with General Public License.
' Any derivatives of this software must remain OpenSource and
' must be distributed at no charge.
' (See license.txt for additional information)
'
' See Credits.txt for the list of contributors.
'
' Change Log:
'--------------------------------------------------------------
' # May 21, 2002 by Rami Kattan
' Fixes few bugs, when filename has ; for password
' # May 30, 2002 by Rami Kattan
' Backup now makes a copy of the original file itself, not
' a compacted version
'==============================================================
bOnlyBackup = (request.querystring("onlybackup") = "true")
%>
<!--#include file="te_config.asp"-->
<!--#include file="te_header.asp"-->
<%
if bAdmin = False then
response.write "Not authorized to view this page."
%><!--#include file="te_footer.asp"--><%
response.end
end if
if not bBulkCompact then
%>
<center><h3><b>Bulk compact/backup is not allowed !!!</b></h3></center>
<% else %>
<br><br>
<table border="0" cellspacing="1" cellpadding="2" bgcolor="#ffe4b5" width="100%">
<tr>
<td class="smallertext">
<a href="index.asp">Home</a> » <a href="te_admin.asp">Connections</a> » <% if bOnlyBackup then response.write "Backup" else response.write "Compact" %> Databases
</td>
<td class="smallerheader" width=130 align=right>
<%
if bProtected then
response.write session("teFullName")
response.write " (<a href=""te_logout.asp"">logout</a>)"
end if
%>
</td>
</tr>
</table>
<img src="images/compact_db.gif" align="right">
<%
dim lConnID
sub ShowForm
%>
<p class="smallertext">
<% If not bOnlyBackup Then %>
All Access Databases will be compacted.<br>
After compacting, the original files will be renamed to ".(date/time).bak" extension as a backup.<br><br>
During the compact process, ".temp.mdb" files will be created, and after the compact is successful, they will be deleted.
<br><br>
Compacting may take some time depending on your databases
sizes. The changes made to the database during the compacting
will not be saved.
<% Else %>
All Access Databases will be backed-up.<br>
The backup files will have the name with ".(date/time).bak" extension as a backup.
<br><br>
Backing up may take some time depending on your databases sizes. The changes made to the database during the backup will not be saved.
<% End If %>
</p>
<p class="smallerheader">
<% If not bOnlyBackup Then %>
Are you sure that you want to compact all databases?
<% Else %>
Are you sure that you want to backup all databases?
<% End If %>
</p>
<a href="te_compactall.asp?<% =request.querystring %>&sure=1">Yes</a>
<a href="<%=request.servervariables("http_referer")%>">No</a>
<%
end sub
if request("sure")<>"" then
%>
<h1><a name="top">Compact Databases</a></h1>
<p>Please wait, compacting loaded connections...</p>
<p> </p>
<%
For lConnID = 1 to iTotalConnections
if arrType(lConnID) = tedbAccess Then
Compact lConnID
end if
Next
Response.Write "<P><B>Complete</B>"
else
ShowForm
end if
Sub RenameFile(sFrom, sTo)
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
sDateTimeStamp = "." & year(now) & LeadingZero(month(now),2) & LeadingZero(day(now),2) & "-" & LeadingZero(hour(now),2) & LeadingZero(minute(now),2) & LeadingZero(second(now),2)
ShortFileName = arrDBs(lConnID)
sFileFromParts = split(ShortFileName, ";")
ShortFileName = sFileFromParts(0)
If not bOnlyBackup Then
fso.MoveFile sTo, left(Server.MapPath(ShortFileName), InStr(Server.MapPath(ShortFileName), ".mdb")-1) & sDateTimeStamp & ".bak"
fso.MoveFile sFrom, sTo
Else
fso.CopyFile sTo, sTo & sDateTimeStamp & ".bak"
End If
End Sub
Sub Compact(lConnID)
ShortFileName = arrDBs(lConnID)
sFileFromParts = split(ShortFileName, ";")
ShortFileName = sFileFromParts(0)
If not bOnlyBackup Then
response.write "<p>Compacting '<b>" & arrDesc(lConnID) & "</b>'..."
else
response.write "<p>Backing up '<b>" & arrDesc(lConnID) & "</b>'..."
end if
sFileFrom = Server.MapPath(ShortFileName)
sFileTo = left(sFileFrom, InStr(sFileFrom, ".mdb")-1) & ".temp.mdb"
If not bOnlyBackup Then
sConnFrom = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & sFileFrom
sConnTo = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & sFileTo
set jro = server.createobject("jro.JetEngine")
jro.CompactDatabase sConnFrom, sConnTo
if err <> 0 then
bError = True
response.write "Error Compacting Database:<br>" & err.description
end if
err.clear
end if
RenameFile sFileTo, sFileFrom
if err <> 0 then
bError = True
response.write "Error Renaming Tempory File:<br>" & err.description
end if
if not bError then
If not bOnlyBackup Then
response.write "<br>Compacting successful."
else
response.write "<br>Backing up successful."
end if
else
response.write "<br>Errors occured."
end if
response.write "</p>" & vbCrLf
end sub
%>
<br><br>
<% end if %>
<!--#include file="te_footer.asp"-->