asp文件连接mysql,ASP连接数据库的一个路径问题

复制内容到剪贴板

ad206c21bb81a1fb36694225bbbf5f6f.gif程序代码

'定义数据库类别,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

%>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值