-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathte_compactdb.asp
More file actions
144 lines (131 loc) · 4.76 KB
/
te_compactdb.asp
File metadata and controls
144 lines (131 loc) · 4.76 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
<%
'==============================================================
' TableEditoR 0.81 Beta
' http://www.2enetworx.com/dev/projects/tableeditor.asp
'--------------------------------------------------------------
' File: te_compactdb.asp
' Description: Compacts an Access Mdb file
' Initiated By Hakan Eskici on Nov 01, 2000
'--------------------------------------------------------------
' 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:
'--------------------------------------------------------------
' # April 18, 2002 by Rami Kattan
' Temporary files are in the same folder as the database
' as some ISP doesn't allow write to normal html folders
' # 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"-->
<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" %> Database
</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">
<%
lConnID = request("cid")
on error resume next
sub ShowForm
%>
<p class="smallertext">
<% if not bOnlyBackup Then %>
The original database "<b><%=sFileFrom%></b>" will be compacted.<br>
After compacting, the original file will be renamed to ".(date/time).bak" extension as a backup.<br><br>
During the compact process, a ".temp.mdb" file will be created, and after the compact is successful, it will be deleted.
<br><br>
Compacting may take some time depending on your database size. The changes made to the database during the compact will not be saved.
<% else %>
The original database "<b><%=sFileFrom%></b>" will be backed-up.<br>
The backup file will have the name with ".(date/time).bak" extension as a backup.
<br><br>
Backing up may take some time depending on your database size. 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 the database?
<% Else %>
Are you sure that you want to backup the database?
<% End If %>
</p>
<a href="te_compactdb.asp?<%=request.querystring%>&sure=1">Yes</a>
<a href="<%=request.servervariables("http_referer")%>">No</a>
<%
end sub
ShortFileName = arrDBs(lConnID)
sFileFromParts = split(ShortFileName, ";")
ShortFileName = sFileFromParts(0)
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)
If not bOnlyBackup Then
fso.MoveFile sTo, Server.MapPath(ShortFileName & sDateTimeStamp & ".bak")
fso.MoveFile sFrom, sTo
Else
fso.CopyFile sTo, sTo & sDateTimeStamp & ".bak"
End If
End Sub
sFileFrom = Server.MapPath(ShortFileName)
sFileTo = left(sFileFrom, InStr(sFileFrom, ".mdb")-1) & ".temp.mdb"
sConnFrom = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & sFileFrom
sConnTo = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & sFileTo
if request("sure")<>"" then
if bTableEdit then
If not bOnlyBackup Then
set jro = server.createobject("jro.JetEngine")
jro.CompactDatabase sConnFrom, sConnTo
if err <> 0 then
bError = True
response.write "Error:<br>" & err.description
end if
end if
RenameFile sFileTo, sFileFrom
if err <> 0 then
bError = True
response.write "Error:<br>" & err.description
end if
if not bError then
If not bOnlyBackup Then
response.write "<br><br>Compacting successful."
Else
response.write "<br><br>Backing up successful."
End If
else
response.write "<br><br>Errors occured."
end if
else
response.write "You dont have permissions to compact databases."
end if
else
ShowForm
end if
%>
<br><br>
<!--#include file="te_footer.asp"-->