数据库连接出错请打开conn.asp文件检查连接字串。-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

数据库连接出错请打开conn.asp文件检查连接字串。

丁阿龙 2015-11-09 13:24:28 13249
网站能打开 后台asp 出现错误 数据库连接出错,请打开conn.asp文件检查连接字串。 QQ38293015
<%@ LANGUAGE = VBScript CodePage = 936%>
<%
Option Explicit
Dim startime,Conn,db,Connstr,Ask_db,Ask_Conn
Response.Buffer = True
Response.charset="gb2312"
startime = Timer()
'--定义数据库类别,1为SQL数据库,0为Access数据库
Const isSqlDataBase = 0


Dim NowString,NewAsp,MyAppPath,AdminPath
MyAppPath = "":AdminPath = ""
'-- 是否开启伪静态功能(False=否,True=是)
Const IsURLRewrite = False
'--系统XML版本设置,最低版本 Const MsxmlVersion=""
Const MsxmlVersion = ".3.0"
'--模板缓存模式,0=不缓存
Const TPLCacheMode = 0
'--验证码文件路径
Const CodeFilePath = "common/getcode.asp"


If IsSqlDataBase = 1 Then
    '-----------------------SQL数据库连接参数---------------------------------------
    NowString = "GetDate()"
    '--SQL数据库连接参数:数据库名(SqlDatabaseName)、用户名(SqlUsername)、用户密码(SqlPassword)
    '--连接名(SqlLocalName)(本地用(local),外地用IP)
    Const SqlDatabaseName = "newasp"
    Const SqlUsername = "sa"
    Const SqlPassword = "newasp"
    Const SqlLocalName = "(local)"
    '-------------------------------------------------------------------------------
Else
    '-----------------------ACCESS数据库连接----------------------------------------
    NowString = "Now()"
    '--ACCESS数据库连接路径;数据库默认在database目录,第一次使用请修改默认数据库名或路径
    '--数据库路径可以使用绝对路径
    db = "database/caonimab.mdb"
    '-------------------------------------------------------------------------------
End If


Dim CJ_DBPath
'-- 采集数据库连接路径
CJ_DBPath = "database/#Collection.resx"


Sub ConnectionDatabase()
    On Error Resume Next
    Set Conn = NewAsp.CreateAXObject("ADODB.Connection")
    If IsSqlDataBase = 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=" & ChkMapPath(MyAppPath & db)
    End If
    Conn.Open Connstr
    If Err Then
        Err.Clear
        Set Conn = Nothing
        Response.Write "数据库连接出错,请打开conn.asp文件检查连接字串。"
        Response.End
    End If
End Sub


'--定义问吧数据库类别,1为SQL数据库,0为Access数据库
Const AskIsSqlDataBase = 0
Dim Ask_SqlDatabaseName,Ask_SqlPassword,Ask_SqlUsername,Ask_SqlLocalName


Sub Ask_ConnectionDatabase()
    Dim Ask_Connstr
    If AskIsSqlDataBase = 1 Then
        '问吧SQL数据库连接参数:数据库名、用户名、用户密码、连接名(本地用local,外地用IP)
        Ask_SqlDatabaseName = "newasp"
        Ask_SqlUsername = "sa"
        Ask_SqlPassword = "newasp"
        Ask_SqlLocalName = "(local)"
        Ask_Connstr = "Provider = Sqloledb; User ID = " & Ask_SqlUsername & "; Password = " & Ask_SqlPassword & "; Initial Catalog = " & Ask_SqlDatabaseName & "; Data Source = " & Ask_SqlLocalName & ";"
    Else
        'ACCESS数据库连接字符串
        Ask_db = "ask/data/ask_newasp.resx"
        Ask_Connstr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & ChkMapPath(MyAppPath & Ask_db)
    End If
    On Error Resume Next
    Set Ask_Conn = NewAsp.CreateAXObject("ADODB.Connection")
    Ask_Conn.Open Ask_Connstr
    If Err Then
        err.Clear
        Set Ask_Conn = Nothing
        Response.Write "问吧数据库连接出错,请检查连接字串。"
        Response.End
    End If
End Sub
'================================================
' 函数名:ChkMapPath
' 作  用:相对路径转换为绝对路径
' 参  数:strPath ----原路径
' 返回值:绝对路径
'================================================
Function ChkMapPath(ByVal strPath)
    Dim fullPath
    strPath = Replace(Replace(Trim(strPath), "/", "\"), "\\", "\")


    If strPath = "" Then strPath = "."
    If InStr(strPath,":\") = 0 Then
        fullPath = Server.MapPath(strPath)
    Else
        strPath = Replace(strPath,"..\","")
        fullPath = Trim(strPath)
        If Right(fullPath, 1) = "\" Then
            fullPath = Left(fullPath, Len(fullPath) - 1)
        End If
    End If
    ChkMapPath = fullPath
End Function
%>
<script Language="JScript" runat="server">
function CloseConn(){
    try{
        Conn.close();
        Conn = null;
    }catch(e){}
}
function Ask_CloseConn(){
    try{
        Ask_Conn.close();
        Ask_Conn = null;
    }catch(e){}
}
</script>
SQL XML 缓存 开发框架 .NET 数据库连接 数据库 数据安全/隐私保护 数据格式
分享到
取消 提交回答
全部回答(2)
  • 丁阿龙
    2015-11-09 13:38:55
    回 1楼梦丫头的帖子
    后台asp格式的

    -------------------------

    回 1楼梦丫头的帖子
    源码是我在我空间上下载下来的,在空间用的好好的
    0 0
  • 梦丫头
    2015-11-09 13:35:14
    看你数据是用什么的。填写正确就可以了

    -------------------------

    回 2楼(丁阿龙) 的帖子
    你数据库用的是什么类型?

    -------------------------

    回 4楼(丁阿龙) 的帖子
    你空间用什么数据库?
    0 0
添加回答
数据库
使用钉钉扫一扫加入圈子
+ 订阅

分享数据库前沿,解构实战干货,推动数据库技术变革

推荐文章
相似问题