当前位置:错新网文章中心网站开发Asp → 压缩并修复Access数据库(推荐)

压缩并修复Access数据库(推荐)

减小字体 增大字体 作者:admin  来源:www.hack50.com  发布时间:2012-5-6 9:46:05
Compact and Repair


You can use the "Compact and Repair" function in Access from ASP code. The following code is an example of
how this can be done. Note that when you decide to "Compact and Repair" your Access database, some
autonumbers can be changed. Access makes all autonumbers consecutive.
This code uses one database, but I'm sure the code can easily be changed so that the listbox displays, for
example, all the databases in one folder.


<%

Const Jet_Conn_Partial = "Provider=Microsoft.Jet.OLEDB.4.0; Data source="
Dim strDatabase, strFolder, strFileName

'#################################################
'# Edit the following two lines
'# Define the full path to where your database is
strFolder = "F:\InetPub\wwwroot\_db\"
'# Enter the name of the database
strDatabase = "YourAccessDatabase.mdb"
'# Stop editing here
'##################################################

Private Sub dbCompact(strDBFileName)
Dim SourceConn
Dim DestConn
Dim oJetEngine
Dim oFSO

SourceConn = Jet_Conn_Partial & strFolder & strDatabase
DestConn = Jet_Conn_Partial & strFolder & "Temp" & strDatabase

Set oFSO = Server.CreateObject("scripting.FileSystemObject")
Set oJetEngine = Server.CreateObject("JRO.JetEngine")

With oFSO

If Not .FileExists(strFolder & strDatabase) Then
Response.Write ("Not Found: " & strFolder & strDatabase)
Stop
Else
If .FileExists(strFolder & "Temp" & strDatabase) Then
Response.Write ("Something went wrong last time " _
& "Deleting old database... Please try again")
.DeleteFile (strFolder & "Temp" & strDatabase)
End If
End If
End With

With oJetEngine
.CompactDatabase SourceConn, DestConn
End With

oFSO.DeleteFile strFolder & strDatabase
oFSO.MoveFile strFolder & "Temp" _
& strDatabase, strFolder& strDatabase

Set oFSO = Nothing
Set oJetEngine = Nothing
End Sub

Private Sub dbList()
Dim oFolders
Set oFolders = Server.CreateObject("scripting.FileSystemObject")
Response.Write ("<Select Name=""DBFileName"">")
For Each Item In oFolders.GetFolder(strFolder).Files
If LCase(Right(Item, 4)) = ".mdb" Then
Response.Write ("<Option Value=""" & Replace(Item, strFolder, "") _
& """>" & Replace(Item, strFolder, "") & "</Option>")
End If
Next
Response.Write ("</Select>")

Set oFolders = Nothing
End Sub


%>
<%
' Compact database and tell the user the database is optimized
Select Case Request.form("cmd")
Case "Compact"
dbCompact Request.form("DBFileName")
Response.Write ("Database " & Request.form("DBFileName") & " is optimized.")
End Select
%>

<p><font size="4">Compact and repair database</font></p>
<form method="POST" action="">
<p><%dbList%><input type="submit" value="Compact" name="cmd"></p>
</form>


本文引用网址:

在下列搜索引擎中搜索“压缩并修复Access数据库(推荐)”的相关信息:

谷歌搜索 百度搜索 雅虎搜索 搜狗搜索 搜搜搜索 必应搜索 有道搜索
你可能还喜欢以下文章
  • 1四川美院女生遭前男友发艳照报...
  • 2林心如艳照 林心如早年裸照性感...
  • 3杨棋涵鸭店门qvod视频 杨棋涵不...
  • 4女中学生遭同学扒光衣裤后凌辱...
  • 5武汉工程大学新生爆奶门 林晨钰...
  • 1如何搭建第一个网站?做网站有...
  • 2网络红人如何赚钱?我要成为网...
  • 3说说"电视棒"为什么卖得这么火...
  • 4百度联盟:哪些做法会被认为是...
  • 5怎么用微博赚钱?微博能赚钱吗...
  • 1中国女大学生的淫靡生活
  • 2嫩白少妇与猛男户外疯狂车震遭...
  • 3让爱升华的真人爱爱姿势教学
  • 4情侣酒店激情性爱 上演限制级影...
  • 5偷拍男女练功房里的那点事 看后...
  • 1如何做服务器安全维护?有哪些...
  • 2Windows Server 2003 安全性指...
  • 3用Webmin和VSFTP搭建FTP服务器...
  • 4历代Windows操作系统大观
  • 5菜鸟入门之centos的文件夹权限...
  • 赞助商广告

    图片文章导读