手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网络编程>Asp编程>列表

一个比较实用的asp函数集合类

来源:互联网 作者:west263.com 时间:2008-02-23
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

'******************************
Public Function ChkPost()
Dim Server_v1,Server_v2
ChkPost=False
Server_v1=CStr(Request.ServerVariables("HTTP_REFERER"))
Server_v2=CStr(Request.ServerVariables("SERVER_NAME"))
If Mid(Server_v1,8,Len(Server_v2))=Server_v2 Then ChkPost=True
End Function

'******************************
'名称: AddErrorCode
'参数:ErrCode
'返回值:ErrCodes
'创建时间:2005年5月3日
'作用:添加错误代码到ErrCodes中
'******************************
Public Sub AddErrorCode(ErrCode)
If ErrCodes="" Then
ErrCodes=ErrCode
Else
ErrCodes=ErrCodes & "," & ErrCode
End If
End Sub

'******************************
'名称: ShowErrMsg
'参数:NULL
'返回值:NULL
'创建时间:2005年5月3日
'作用:显示详细的错误信息
'******************************
Public Function ShowErrMsg()
If NOT p_Debug Then On Error Resume Next
If ErrCodes<>"" Then
iErrCodes=Split(ErrCodes,",",-1,Binary)
For i=LBound(iErrCodes) To UBound(iErrCodes)
tmpErrCode=CLng(iErrCodes(i))
If IsNumeric(tmpErrCode) Then
ErrMsg=ErrMsg & ErrDetails(tmpErrCode)
End If
Next
End If
ShowErrMsg=ErrMsg
End Function

'******************************
'名称: ConnectionDataBase
'参数:DataBase,p_dbUserID,p_dbPassword,p_dbType
'返回值:NULL
'作用:连接到数据库
'创建时间:2005年5月6日
'******************************
Public Function ConnectionDataBase(param_DataBase,param_dbUserID,param_dbPassword,param_dbType)
If Not p_Debug Then On Error Resume Next
ClientConnected
If IsNumeric(param_dbType) Then
Set objConn=Server.CreateObject("ADODB.Connection")
objConn.ConnectionTimeOut=10 '设置连接超时为10秒
dbPath=Server.MapPath(p_dbFolder&param_DataBase)
'Response.Write dbPath
Select Case param_dbType
Case 11: 'Access Data Base(OLEDB)
ConnStr="Provider=Microsoft.Jet.Oledb.4.0;Data Source="&dbPath&";User ID="&param_dbUserID&";Password="&param_dbPassword&""
Case 21: 'SQL Server (OLEDB)
ConnStr="Provider=SQLOLEDB;Initial Catalog="&param_DataBase&";Data Source="&p_sqlDataSource&";User ID="&param_dbUserID&";Password="&param_dbPassword&""
Case 12: 'Access Data Base(ODBC)
ConnStr="Driver={Microsoft Access Driver (*.mdb)};DBQ="&dbPath&";User ID="&param_dbUserID&";Password="&param_dbPassword
Case 22: 'SQL Server (ODBC)
ConnStr="Driver={SQL Server};DataBase="&param_DataBase&";Server="&p_sqlDataSource&";User ID="&param_dbUserID&";Password="&param_dbPassword&""
Case Else:
AddErrorCode(100)
If p_Debug Then Response.Write ShowErrMsg()
'Exit Function
End Select
objConn.ConnectionString=ConnStr
objConn.Open
Set ConnectionDataBase=objConn
If Err Then
Err.Clear

If SaveLog Then
tmpMsg="数据库连接时出现错误,请检查您的查询代码是否正确。<br>基于安全的理由,只显示本信息,要查看详细的错误信息,请设置dsj.Debug=True"
cmd="Execute the command of :"&param_dbtype
Response.Write SaveSQLLog(cmd,tmpMsg)
Else
Response.Write "数据库连接时出现错误,请检查您的查询代码是否正确。"
End If
AddErrorCode(101)
Set objConn=Nothing
Response.End()
End If
End If
End Function

'******************************
'名称: SaveSQLLog
'参数:sCommand,Msg
'返回值:msg
'作用:存储日志
'创建时间:2005年5月6日
'******************************
Public Function SaveSQLLog(sCommand,Msg)
If Not p_Debug Then On Error Resume Next
logDB="DSJ_SQLLog.mdb"
'ConnectionDataBase logDB,p_dbUserID,p_dbPassword,12
logConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(p_dbFolder & logDB)
Set logConn = Server.CreateObject("ADODB.Connection")
logConn.Open logConnStr
If SaveLog Then
Dim logCmd
logCmd="INSERT INTO DSJ_SQL_Log (Command,ScriptName,logUser,IP) VALUES "
logCmd=logCmd & "('" & Replace(Left(sCommand,255),"'","''") &"','" & (ScriptFolder & ScriptName) &"','" & Session("User") & "','"& GetIP & "')"
'Response.Write "Need to execute command is:<br><font color=red>" & logCmd & "</font><BR>"
logConn.Execute(logCmd)
End If
logConn.Close
Set logConn=Nothing
SaveSQLLog=msg
SQLQueryNum=SQLQueryNum 1
End Function

'******************************
'名称: ExecuteCmd
'参数:cmd
'返回值:RecordSet
'作用:返回由cmd创建的记录集
'创建时间:2005年5月6日
'******************************
Public Function ExecuteCmd(cmd)
If NOT IsObject(objConn) Then ConnectionDataBase p_DataBase,p_dbUserID,p_dbPassword,p_dbType
If NOT p_Debug Then On Error Resume Next
ClientConnected
Set ExecuteCmd=objConn.Execute(cmd)

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!