<%
Dim str_db_path_name
str_db_path_name = server.mapPath(".") & "\" & "baza.mdb"
'Dimension variables
Dim objJetEngine
Dim objFSO
Dim strCompactDB
DIm strCon
DIm adoCon
%>
<%
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.connectionstring = strCon
strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & str_db_path_name
%>
<%
'Pokretanje compact i repair funkcije
If Request.Form("postBack") Then %>
<ol><%
'kreiranje FSO objekta
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'backup baze
objFSO.CopyFile str_db_path_name, Replace(str_db_path_name, ".mdb", "-backup.mdb", 1, -1, 1)
Response.Write(" <li class=""bold"">Napravljen je backup baze podataka na:-<br/><span class=""smText"">" & Replace(str_db_path_name, ".mdb", "-backup.mdb", 1, -1, 1) & "</span><br /><br /></li>")
'kreiranje JET engine objekta
Set objJetEngine = Server.CreateObject("JRO.JetEngine")
'odrediste i naziv kompaktovane baze
strCompactDB = Replace(str_db_path_name, ".mdb", "-tmp.mdb", 1, -1, 1)
'kompaktovanje
objJetEngine.CompactDatabase strCon, "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & strCompactDB
'ispis teksta kreiranja nove kompaktovanja baze
Response.Write(" <li class=""bold"">Nova optimizovana baza:-<br/><span class=""smText"">" & strCompactDB & "</span><br /><br /></li>")
'resetovanje Jet objekta
Set objJetEngine = Nothing
'brisanje stare baze
objFSO.DeleteFile str_db_path_name
'ispis teksta brisanja stare baze
Response.Write(" <li class=""bold"">Nova ne optimizovana baza je obrisana:-<br/><span class=""smText"">" & str_db_path_name & "</span><br /><br /></li>")
'preimenovanje privremene baze u stari naziv
objFSO.MoveFile strCompactDB, str_db_path_name
'ispis teksta brisanja stare baze
Response.Write(" <li class=""bold"">Izmjenjen je naziv optimizovane baze sa:-<br/><span class=""smText"">" & strCompactDB & "</span><br />na:-<br /><span class=""smText"">" & str_db_path_name & "</span><br /><br /></li>")
'resetovanje FSO objekta
Set objFSO = Nothing
Response.Write("Baza podataka je optimizovana i napravljen je backup!")
%></ol>
<% Else %>
Napomena: Ako optimizacija ne uspije, biće urađen backup baze podataka čiji naziv ima nastavak '-backup.mdb'.
<form action="backup_db.asp" method="post" name="frmCompact" id="frmCompact">
<input name="postBack" type="hidden" id="postBack" value="true">
<input type="submit" name="Submit" value="OPTIMIZUJ I NAPRAVI BACKUP">
</form>
<% End If %>
Aleksandar M.