ASP编程:ASP完成的较复杂的背景办理
优点:简单易学、开发速度快、有很多年“历史”,能找到非常多别人做好的程序来用、配合activeX功能强大,很多php做不到的asp+activeX能做到,例如银行安全控件背景|背景办理简介:毗连各类范例数据库及对数据库操纵的函数上面这部分程序可说是全能的数据库毗连程序几近能够毗连一切的MS数据库,本人拿往研讨吧(这个程序是“ASP网页制造教程”这本书内里的――一本好书):
<%
---------------------------------------------------
FunctionGetMdbConnection(FileName)
DimProvider,DBPath
Provider="Provider=Microsoft.Jet.OLEDB.4.0;"
DBPath="DataSource="&Server.MapPath(FileName)
SetGetMdbConnection=GetConnection(Provider&DBPath)
EndFunction
---------------------------------------------------
FunctionGetSecuredMdbConnection(FileName,Password)
DimProvider,DBPath
Provider="Provider=Microsoft.Jet.OLEDB.4.0;"
DBPath="DataSource="&Server.MapPath(FileName)
SetGetSecuredMdbConnection=GetConnection(Provider&DBPath&";JetOLEDB:DatabasePassword="&Password)EndFunction
---------------------------------------------------
FunctionGetDbcConnection(FileName)
DimDriver,SourceType,DBPath
Driver="Driver={MicrosoftVisualFoxProDriver};"
SourceType="SourceType=DBC;"
DBPath="SourceDB="&Server.MapPath(FileName)
SetGetDbcConnection=GetConnection(Driver&SourceType&DBPath)
EndFunction
---------------------------------------------------
FunctionGetDbfConnection(Directory)
DimDriver,SourceType,DBPath
Driver="Driver={MicrosoftVisualFoxProDriver};"
SourceType="SourceType=DBF;"
DBPath="SourceDB="&Server.MapPath(Directory)
SetGetDbfConnection=GetConnection(Driver&SourceType&DBPath)
EndFunction
---------------------------------------------------
FunctionGetExcelConnection(FileName)
DimDriver,DBPath
Driver="Driver={MicrosoftExcelDriver(*.xls)};"
DBPath="DBQ="&Server.MapPath(FileName)
SetGetExcelConnection=GetConnection(Driver&"ReadOnly=0;"&DBPath)EndFunction
---------------------------------------------------
FunctionGetTextConnection(Directory)
DimDriver,DBPath
Driver="Driver={MicrosoftTextDriver(*.txt;*.csv)};"
DBPath="DBQ="&Server.MapPath(Directory)
SetGetTextConnection=GetConnection(Driver&DBPath)
EndFunction
---------------------------------------------------
FunctionGetSQLServerConnection(Computer,UserID,Password,Db)
DimParams,conn
SetGetSQLServerConnection=Nothing
Params="Provider=SQLOLEDB.1"
Params=Params&";DataSource="&Computer
Params=Params&";UserID="&UserID
Params=Params&";Password="&Password
Params=Params&";InitialCatalog="&Db
Setconn=Server.CreateObject("ADODB.Connection")
conn.OpenParams
SetGetSQLServerConnection=conn
EndFunction
---------------------------------------------------
FunctionGetMdbRecordset(FileName,Source)
SetGetMdbRecordset=GetMdbRs(FileName,Source,2,"")
EndFunction
---------------------------------------------------
FunctionGetMdbStaticRecordset(FileName,Source)
SetGetMdbStaticRecordset=GetMdbRs(FileName,Source,3,"")
EndFunction
---------------------------------------------------
FunctionGetSecuredMdbRecordset(FileName,Source,Password)
SetGetSecuredMdbRecordset=GetMdbRs(FileName,Source,2,Password)EndFunction
---------------------------------------------------
FunctionGetSecuredMdbStaticRecordset(FileName,Source,Password)
SetGetSecuredMdbStaticRecordset=GetMdbRs(FileName,Source,3,Password)EndFunction
---------------------------------------------------
FunctionGetDbfRecordset(Directory,SQL)
SetGetDbfRecordset=GetOtherRs("Dbf",Directory,SQL,2)
EndFunction
---------------------------------------------------
FunctionGetDbfStaticRecordset(Directory,SQL)
SetGetDbfStaticRecordset=GetOtherRs("Dbf",Directory,SQL,3)
EndFunction
---------------------------------------------------
FunctionGetDbcRecordset(FileName,SQL)
SetGetDbcRecordset=GetOtherRs("Dbc",FileName,SQL,2)
EndFunction
---------------------------------------------------
FunctionGetDbcStaticRecordset(FileName,SQL)
SetGetDbcStaticRecordset=GetOtherRs("Dbc",FileName,SQL,3)
EndFunction
---------------------------------------------------
FunctionGetExcelRecordset(FileName,SQL)
SetGetExcelRecordset=GetOtherRs("Excel",FileName,SQL,2)
EndFunction
---------------------------------------------------
FunctionGetExcelStaticRecordset(FileName,SQL)
SetGetExcelStaticRecordset=GetOtherRs("Excel",FileName,SQL,3)
EndFunction
---------------------------------------------------
FunctionGetTextRecordset(Directory,SQL)
SetGetTextRecordset=GetOtherRs("Text",Directory,SQL,2)
EndFunction
---------------------------------------------------
FunctionGetTextStaticRecordset(Directory,SQL)
SetGetTextStaticRecordset=GetOtherRs("Text",Directory,SQL,3)
EndFunction
---------------------------------------------------
FunctionGetSQLServerRecordset(conn,source)
Dimrs
Setrs=Server.CreateObject("ADODB.Recordset")
rs.Opensource,conn,2,2
SetGetSQLServerRecordset=rs
EndFunction
---------------------------------------------------
FunctionGetSQLServerStaticRecordset(conn,source)
Dimrs
Setrs=Server.CreateObject("ADODB.Recordset")
rs.Opensource,conn,3,2
SetGetSQLServerStaticRecordset=rs
EndFunction
---------------------------------------------------
FunctionGetConnection(Param)
Dimconn
OnErrorResumeNext
SetGetConnection=Nothing
Setconn=Server.CreateObject("ADODB.Connection")
IfErr.Number0ThenExitFunction
conn.OpenParam
IfErr.Number0ThenExitFunction
SetGetConnection=conn
EndFunction
---------------------------------------------------
FunctionGetMdbRs(FileName,Source,Cursor,Password)
Dimconn,rs
OnErrorResumeNext
SetGetMdbRs=Nothing
IfLen(Password)=0Then
Setconn=GetMdbConnection(FileName)
Else
Setconn=GetSecuredMdbConnection(FileName,Password)
EndIf
IfconnIsNothingThenExitFunction
Setrs=Server.CreateObject("ADODB.Recordset")
IfErr.Number0ThenExitFunction
rs.Opensource,conn,Cursor,2
IfErr.Number0ThenExitFunction
SetGetMdbRs=rs
EndFunction
---------------------------------------------------
FunctionGetOtherRs(DataType,Path,SQL,Cursor)
Dimconn,rs
OnErrorResumeNext
SetGetOtherRs=Nothing
SelectCaseDataType
Case"Dbf"
Setconn=GetDbfConnection(Path)
Case"Dbc"
Setconn=GetDbcConnection(Path)
Case"Excel"
Setconn=GetExcelConnection(Path)
Case"Text"
Setconn=GetTextConnection(Path)
EndSelect
IfconnIsNothingThenExitFunction
Setrs=Server.CreateObject("ADODB.Recordset")
IfErr.Number0ThenExitFunction
rs.OpenSQL,conn,Cursor,2
IfErr.Number0ThenExitFunction
SetGetOtherRs=rs
EndFunction
---------------------------------------------------
FunctionGetSQLServerRs(Computer,UserID,Password,Db,source,Cursor)
Dimconn,rs
OnErrorResumeNext
SetGetSQLServerRs=Nothing
Setconn=GetSQLServerConnection(Computer,UserID,Password,Db)
IfconnIsNothingThenExitFunction
Setrs=Server.CreateObject("ADODB.Recordset")
IfErr.Number0ThenExitFunction
rs.Opensource,conn,Cursor,2
IfErr.Number0ThenExitFunction
SetGetSQLServerRs=rs
EndFunction
%>
利用办法是――复制上去存成一个文件,然后用#Include“文件名”就能够挪用内里的子程序了。
有甚么成绩能够一同切磋!!!asp对于服务器的要求较高,一般的服务器如果访问量一大就垮了,不得不重启。 我们必须明确一个大方向,不要只是停留在因为学而去学,我们应有方向应有目标. 代码的可重用性差:由于是面向结构的编程方式,并且混合html,所以可能页面原型修改一点,整个程序都需要修改,更别提代码重用了。 ASP(ActiveServerPages)是Microsfot公司1996年11月推出的WEB应用程序开发技术,它既不是一种程序语言,也不是一种开发工具,而是一种技术框架,不须使用微软的产品就能编写它的代码,能产生和执行动态、交互式、高效率的站占服务器的应用程序。 兴趣爱好,那么你无须学编程,申请一个域名和空间,在网上下载一些免费开源的CMS系统,你不用改代码,只须熟悉它们的后台操作,像office一样简单方便,很快就能建一个站点,很多站长都是这样做的 如何更好的使自己的东西看上去很不错等等。其实这些都不是问题的实质,我们可以在实践中不断提升自己,不断充实自己。 以上是语言本身的弱点,在功能方面ASP同样存在问题,第一是功能太弱,一些底层操作只能通过组件来完成,在这点上是远远比不上PHP/JSP,其次就是缺乏完善的纠错/调试功能,这点上ASP/PHP/JSP差不多。 弱类型造成潜在的出错可能:尽管弱数据类型的编程语言使用起来回方便一些,但相对于它所造成的出错几率是远远得不偿失的。 ASP.Net摆脱了以前ASP使用脚本语言来编程的缺点,理论上可以使用任何编程语言包括C++,VB,JS等等,当然,最合适的编程语言还是MS为.NetFrmaework专门推出的C(读csharp),它可以看作是VC和Java的混合体吧。
页:
[1]