|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
优点:简单易学、开发速度快、有很多年“历史”,能找到非常多别人做好的程序来用、配合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对于服务器的要求较高,一般的服务器如果访问量一大就垮了,不得不重启。 |
|