复制内容到剪贴板
程序代码
'定义数据库类别,1为SQL数据库,0为Access数据库
Const IsSQLDataBase = 0
If IsSQLDataBase = 1 Then
'SQL数据库设置
'数据库名(SQLDatabaseName)
Const SQLDatabaseName = "cj_2007"
'用户密码(SQLPassword)
Const SQLPassword = ""
'用户名(SQLUsername)
Const SQLUsername = "sa"
'连接名(SQLLocalName)(本地用local,外地用ip)
Const SQLLocalName = "(local)"
'=====================================================================
Else
'Access数据库设置
'用户第一次使用请修改本处数据库地址并相应修改data目录中数据库名称
'相对当前目录下绝对路径
Const DataPath = "data/#123zh.mdb"
'===================================================================
End If
ConnectionDatabase '执行数据库连接
Sub ConnectionDatabase
On Error Resume Next
Set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnStr(IsSQLDataBase)
If Err Then
err.Clear : Set Conn = Nothing
res "数据库连接错误,请与网站管理员联系!",1
Response.End
End If
End Sub
'***********************************************
'函数名:ConnStr
'作 者:静¢脉(hayden)
'原 文: http://www.mysuc.com/article.asp?id=140
'时 间: 2007.11.23
'功 能:生成数据库连接字符串
'形 参:str1 ----数据库类型 1为SQL 0为ACC
'返回值:数据库连接字符串
'***********************************************
Function ConnStr(str1)
If str1 = 1 Then
ConnStr = "Provider = SQLoledb; "&_
"User ID = " & SQLUsername & "; "&_
"Password = " & SQLPassword & "; "&_
"Initial Catalog = " & SQLDatabaseName & "; "&_
"Data Source = " & SQLLocalName & ";"
Else
ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0; "&_
"Data Source = " & Server.MapPath(Autopath(DataPath))
End If
End Function
'***********************************************
'函数名:Autopath
'作 者:静¢脉(hayden)
'原 文: http://www.mysuc.com/article.asp?id=140
'时 间: 2007.11.23
'功 能:自动对应数据库路径
'形 参:str1 ----数据库路径
'返回值:正确的数据库路径
'***********************************************
Function Autopath(str1)
Autopath=str1
If Left(Autopath,1)<>"/" or Left(Autopath,1)<>"\" Then
If IsObjInstalled("Scripting.FileSystemObject") Then
If ReportFileStatus(str1)=-1 Then Autopath="../"&Autopath
Else
Dim ScriptAddress,inpath
ScriptAddress = CStr(Request.ServerVariables("SCRipT_NAME")) '虚拟目录+文件
inpath=Split(ScriptAddress,"/")
If inpath(UBound(inpath)-1)="admin" Then Autopath="../"&Autopath '判断是否在后台目录下(admin)
End If
End If
End Function
'***********************************************
'函数名:ReportFileStatus
'功 能:判断文件是否存在
'形 参:FileName ----文件名
'返回值:成功为1,失败为-1
'***********************************************
Function ReportFileStatus(FileName)
FileName=Server.mappath(FileName)
ReportFileStatus = -1
If IsObjInstalled("Scripting.FileSystemObject") Then
Dim fun_fso
set fun_fso = Server.CreateObject("scripting.filesystemobject")
If (fun_fso.FileExists(FileName)) Then ReportFileStatus = 1
End If
End Function
'***********************************************
'函数名:IsObjInstalled
'功 能:判断组件支持
'形 参:strClassString ----组件名称
'返回值:成功为true,失败为false
'***********************************************
Function IsObjInstalled(strClassString)
On Error Resume Next
IsObjInstalled = False
Err = 0
Dim xTestObj
Set xTestObj = Server.CreateObject(strClassString)
If 0 = Err Then IsObjInstalled = True
Set xTestObj = Nothing
Err = 0
End Function
%>