您好,欢迎访问三七文档
ASP编程技巧大全%''#######以下是一个类文件,下面的注解是调用类的方法################################################''#注意:如果系统不支持建立Scripting.FileSystemObject对象,那么数据库压缩功能将无法使用''#Access数据库类''#CreateDbFile建立一个Access数据库文件''#CompactDatabase压缩一个Access数据库文件''#建立对象方法:''#Seta=NewDatabaseTools''#by(萧寒雪)s.f.''#########################################################################################ClassDatabaseToolsPublicfunctionCreateDBfile(byValdbFileName,byValDbVer,byValSavePath)''建立数据库文件''IfDbVeris0ThenCreateAccess97dbFile''IfDbVeris1ThenCreateAccess2000dbFileOnerrorresumeNextIfRight(SavePath,1)\OrRight(SavePath,1)/ThenSavePath=Trim(SavePath)&\IfLeft(dbFileName,1)=\OrLeft(dbFileName,1)=/ThendbFileName=Trim(Mid(dbFileName,2,Len(dbFileName)))IfDbExists(SavePath&dbFileName)ThenResponse.Write(对不起,该数据库已经存在!)CreateDBfile=FalseElseDimCaSetCa=Server.CreateObject(ADOX.Catalog)IfErr.number0ThenResponse.Write(无法建立,请检查错误信息&Err.number&&Err.Description)Err.ClearExitfunctionEndIfIfDbVer=0ThencallCa.Create(Provider=Microsoft.Jet.OLEDB.3.51;DataSource=&SavePath&dbFileName)ElsecallCa.Create(Provider=Microsoft.Jet.OLEDB.4.0;DataSource=&SavePath&dbFileName)EndIfSetCa=NothingCreateDBfile=TrueEndIfEndfunctionPublicfunctionCompactDatabase(byValdbFileName,byValDbVer,byValSavePath)''压缩数据库文件''0为access97''1为access2000OnErrorresumenextIfRight(SavePath,1)\OrRight(SavePath,1)/ThenSavePath=Trim(SavePath)&\IfLeft(dbFileName,1)=\OrLeft(dbFileName,1)=/ThendbFileName=Trim(Mid(dbFileName,2,Len(dbFileName)))IfDbExists(SavePath&dbFileName)ThenResponse.Write(对不起,该数据库已经存在!)CompactDatabase=FalseElseDimCdSetCd=Server.CreateObject(JRO.JetEngine)IfErr.number0ThenResponse.Write(无法压缩,请检查错误信息&Err.number&&Err.Description)Err.ClearExitfunctionEndIfIfDbVer=0ThencallCd.CompactDatabase(Provider=Microsoft.Jet.OLEDB.3.51;DataSource=&SavePath&dbFileName,Provider=Microsoft.Jet.OLEDB.3.51;DataSource=&SavePath&dbFileName&.bak.mdb;JetOLEDB;EncryptDatabase=True)ElsecallCd.CompactDatabase(Provider=Microsoft.Jet.OLEDB.4.0;DataSource=&SavePath&dbFileName,Provider=Microsoft.Jet.OLEDB.4.0;DataSource=&SavePath&dbFileName&.bak.mdb;JetOLEDB;EncryptDatabase=True)EndIf''删除旧的数据库文件callDeleteFile(SavePath&dbFileName)''将压缩后的数据库文件还原callRenameFile(SavePath&dbFileName&.bak.mdb,SavePath&dbFileName)SetCd=FalseCompactDatabase=TrueEndIfendfunctionPublicfunctionDbExists(byValdbPath)''查找数据库文件是否存在OnErrorresumeNextDimcSetc=Server.CreateObject(ADODB.Connection)c.OpenProvider=Microsoft.Jet.OLEDB.4.0;DataSource=&dbPathIfErr.number0ThenErr.ClearDbExists=falseelseDbExists=TrueEndIfsetc=nothingEndfunctionPublicfunctionAppPath()''取当前真实路径AppPath=Server.MapPath(./)EndfunctionPublicfunctionAppName()''取当前程序名称AppName=Mid(Request.ServerVariables(SCRIPT_NAME),(InStrRev(Request.ServerVariables(SCRIPT_NAME),/,-1,1))+1,Len(Request.ServerVariables(SCRIPT_NAME)))EndFunctionPublicfunctionDeleteFile(filespec)''删除一个文件DimfsoSetfso=CreateObject(Scripting.FileSystemObject)IfErr.number0ThenResponse.Write(删除文件发生错误!请查看错误信息&Err.number&&Err.Description)Err.ClearDeleteFile=FalseEndIfcallfso.DeleteFile(filespec)Setfso=NothingDeleteFile=TrueEndfunctionPublicfunctionRenameFile(filespec1,filespec2)''修改一个文件DimfsoSetfso=CreateObject(Scripting.FileSystemObject)IfErr.number0ThenResponse.Write(修改文件名时发生错误!请查看错误信息&Err.number&&Err.Description)Err.ClearRenameFile=FalseEndIfcallfso.CopyFile(filespec1,filespec2,True)callfso.DeleteFile(filespec1)Setfso=NothingRenameFile=TrueEndfunctionEndClass%现在已可以压缩有密码的数据库,代码如下,但是压缩之后的数据库密码就没有了!如何解决?%ConstJET_3X=4FunctionCompactDB(dbPath,boolIs97)Dimfso,Engine,strDBPathstrDBPath=left(dbPath,instrrev(DBPath,\))Setfso=CreateObject(Scripting.FileSystemObject)Iffso.FileExists(dbPath)ThenSetEngine=CreateObject(JRO.JetEngine)IfboolIs97=TrueThenEngine.CompactDatabaseProvider=Microsoft.Jet.OLEDB.4.0;DataSource=&dbpath,_Provider=Microsoft.Jet.OLEDB.4.0;JetOLEDB:DatabasePassword=''XXXXXXXX'';DataSource=&strDBPath&temp.mdb;_&JetOLEDB:EngineType=&JET_3XElseEngine.CompactDatabaseProvider=Microsoft.Jet.OLEDB.4.0;JetOLEDB:DatabasePassword=''XXXXXXXX'';DataSource=&dbpath,_Provider=Microsoft.Jet.OLEDB.4.0;DataSource=&strDBPath&temp.mdbEndIffso.CopyFilestrDBPath&temp.mdb,dbpathfso.DeleteFile(strDBPath&temp.mdb)Setfso=nothingSetEngine=nothingCompactDB=你的数据库,&dbpath&,已经压缩成功!&vbCrLfElseCompactDB=数据库名称或路径不正确.请重试!&vbCrLfEndIfEndFunction%asp编程有用的例子(一)1.如何用Asp判断你的网站的虚拟物理路径答:使用Mappath方法palign=centerfontsize=4face=ArialbThePhysicalpathtothisvirtualwebsiteis:/b/fontfontcolor=#FF0000size=6face=Arial%=Server.MapPath(\)%/font/p2.我如何知道使用者所用的浏览器?答:使用theRequestobject方法strBrowser=Request.ServerVariables(HTTP_USER_AGENT)IfInstr(strBrowser,MSIE)0ThenResponse.redirect(ForMSIEOnly.htm)ElseResponse.redirect(ForAll.htm)EndIf3.如何计算每天的平均反复访问人数答:解决方法%startdate=DateDiff(d,Now,01/01/1990)ifstrdate0thenstartdate=startdate*-1avgvpd=Int((usercnt)/startdate)%显示结果%response.write(avgvpd)%thatisit.thispagehavebeenviewedsinceNovember10,19984.如何显示随机图象%dimp,ppic,dpicppic=12randomizep=Int((ppic*rnd)+1)dpic=graphix/randompics/&p&.gif%显示imgsrc=
本文标题:ASP编程技巧大全
链接地址:https://www.777doc.com/doc-5126892 .html