上一篇:利用 WSH 作定时工作流程 >>
纯编码实现Access数据库的建立或压缩
#######以下是一个类文件,下面的注解是调用类的方法################################################
# 注意:如果系统不支持建立scripting.filesystemobject对象,那么数据库压缩功能将无法使用
# access 数据库类
# createdbfile 建立一个access 数据库文件
# compactdatabase 压缩一个access 数据库文件
# 建立对象方法:
# set a = new databasetools
# by (萧寒雪) s.f.
#########################################################################################
class databasetools
public function createdbfile(byval dbfilename,byval dbver,byval savepath)
建立数据库文件
if dbver is 0 then create access97 dbfile
if dbver is 1 then create access2000 dbfile
on error resume next
if right(savepath,1)<>"\" or right(savepath,1)<>"/" then savepath = trim(savepath) & "\"
if left(dbfilename,1)="\" or left(dbfilename,1)="/" then dbfilename = trim(mid(dbfilename,2,len(dbfilename)))
if dbexists(savepath & dbfilename) then
response.write ("对不起,该数据库已经存在!")
createdbfile = false
else
dim ca
set ca = server.createobject("adox.catalog")
if err.number<>0 then
response.write ("无法建立,请检查错误信息
" & err.number & "
" & err.description)
err.clear
exit function
end if
if dbver=0 then
call ca.create("provider=microsoft.jet.oledb.3.51;data source=" & savepath & dbfilename)
else
call ca.create("provider=microsoft.jet.oledb.4.0;data source=" & savepath & dbfilename)
end if
set ca = nothing
createdbfile = true
end if
end function
public function compactdatabase(byval dbfilename,byval dbver,byval savepath)
压缩数据库文件
0 为access 97
1 为access 2000
on error resume next
if right(savepath,1)<>"\" or right(savepath,1)<>"/" then savepath = trim(savepath) & "\"
if left(dbfilename,1)="\" or left(dbfilename,1)="/" then dbfilename = trim(mid(dbfilename,2,len(dbfilename)))
if dbexists(savepath & dbfilename) then
response.write ("对不起,该数据库已经存在!")
compactdatabase = false
else
dim cd
set cd =server.createobject("jro.jetengine")
if err.number<>0 then
response.write ("无法压缩,请检查错误信息
" & err.number & "
" & err.description)
err.clear
exit function
end if
if dbver=0 then
call cd.compactdatabase("provider=microsoft.jet.oledb.3.51;data source=" & savepath & dbfilename,"provider=microsoft.jet.oledb.3.51;data
source=" & savepath & dbfilename & ".bak.mdb;jet oledb;encrypt database=true")
else
call cd.compactdatabase("provider=microsoft.jet.oledb.4.0;data source=" &
savepath & dbfilename,"provider=microsoft.jet.oledb.4.0;data source=" &
savepath & dbfilename & ".bak.mdb;jet oledb;encrypt database=true")
end if
删除旧的数据库文件
call deletefile(savepath & dbfilename)
将压缩后的数据库文件还原
call renamefile(savepath & dbfilename & ".bak.mdb",savepath & dbfilename)
set cd = false
compactdatabase = true
end if
end function
public function dbexists(byval dbpath)
查找数据库文件是否存在
on error resume next
dim c
set c = server.createobject("adodb.connection")
c.open "provider=microsoft.jet.oledb.4.0;data source=" & dbpath
if err.number<>0 then
err.clear
dbexists = false
else
dbexists = true
end if
set c = nothing
end function
public function apppath()
取当前真实路径
apppath = server.mappath("./")
end function
public function appname()
取当前程序名称
appname = mid(request.servervariables("script_name"),(instrrev(request.servervariables("script_name") ,"/",-1,1))+1,len(request.servervariables("script_name")))
end function
public function deletefile(filespec)
删除一个文件
dim fso
set fso = createobject("scripting.filesystemobject")
if err.number<>0 then
response.write("删除文件发生错误!请查看错误信息
" & err.number & "
" & err.description)
err.clear
deletefile = false
end if
call fso.deletefile(filespec)
set fso = nothing
deletefile = true
end function
public function renamefile(filespec1,filespec2)
修改一个文件
dim fso
set fso = createobject("scripting.filesystemobject")
if err.number<>0 then
response.write("修改文件名时发生错误!请查看错误信息
" & err.number & "
" & err.description)
err.clear
renamefile = false
end if
call fso.copyfile(filespec1,filespec2,true)
call fso.deletefile(filespec1)
set fso = nothing
renamefile = true
end function
end class
%>
()
下一篇:一个完整的网上追捕的原程序 >>
相关文章:
- · 编写高质量的VB代码
- · dvbbs绝对背后的微笑
- · 5.PHP的其他功能
- · 4.与数据库的连接
- · 3.从实例开始
- · 2.PHP入门
- · 1.PHP简介
- · 随机头像PHP版
- · 自动跳转中英文页面
- · 从IIS到SQL Server数据库安全
- · 通用数据库显示程序
- · ASP实用函数库
- · 漂亮但不安全的CTB
- · 无组件图片与文本同步存入数据库的最简单的办法
- · 利用PHP创建动态图像
- · 精妙SQL语句
- · 用ASP动态生成JS表单验证代码
- · 用ASP编写网上调查投票系统
- · 轮换的logo显示
- · ip签名探针
- · ASP下载系统防盗链方法
- · ASP开发网页牢记注意事项
- · IIS6.0下ASP的新增功能
- · 图片或banner的随机显示
- · 判断Cookies是否处于开启状态
- · 主页javascript特效19则
- · Script经典文章
- · 用ASP做全文检索
- · WEB应用中报表打印的实现
- · 控制输出字符串长度区别中英文
- · ADO连接数据库字符串大全
- · vbscript与javascript传递变量
- · WSH 直接将查询数据结果生成EXCEL表
- · 树型结构在ASP中的简单解决
- · 用Object for OLE访问Oracle
- · ASP中使用SQL语句
- · 继承派生多态
- · ASP中处理#include
