| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 930 人关注过本帖
标题:这什么这个就连不上数据库
只看楼主 加入收藏
tiankong118
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2008-8-27
收藏
 问题点数:0 回复次数:3 
这什么这个就连不上数据库
<%
'Option Explicit
Response.Buffer = True

'全局变量
Dim showye,page
Dim SqlNowString
Dim SqlBoolStringTrue
Dim SqlBoolStringFalse


Dim Startime
Dim Conn

'定义数据库类别,1为SQL数据库,0为Access数据库
Const CityAdminCSS="<link rel=""stylesheet"" type=""text/css"" href=""/CSS/main.css"">"  
Const IsSqlDataBase = 1

'定义运行模式,测试的时候设置1,正常运行的时候设置为0,不输出错误信息有利于安全,
'========================================================
'程序调试开关,为true 输出错误提示,为false 不输出错误提示
'========================================================
Const IsDeBug = 1
Startime = Timer()


'SQL获取时间函数
If IsSqlDataBase = 1 Then
    SqlNowString = "GetDate()"
    SqlBoolStringTrue="1"
    SqlBoolStringFalse="0"
Else
    SqlNowString = "Now()"
    SqlBoolStringTrue="true"
    SqlBoolStringFalse="false"    
End If

function SqlBoolString(AValue)
 select case CBool(AValue)
 case True
    SqlBoolString= SqlBoolStringTrue
 case False
    SqlBoolString= SqlBoolStringFalse
 end select
end function

'打开数据库
Dim SqlDatabaseName,SqlPassword,SqlUsername,SqlLocalName
Sub ConnectionDatabase
    Dim ConnStr
    If IsSqlDataBase = 1 Then
        'sql数据库连接参数:数据库名、用户密码、用户名、连接名(本地用local,外地用IP)

        SqlDatabaseName = "BIZAD"
        SqlPassword = ""
        SqlUsername = "sa"
        SqlLocalName = "(local)"
        ConnStr = "Provider = Sqloledb; User ID = " & SqlUsername & "; Password = " &

SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source = " & SqlLocalName & ";"
    Else
        '免费用户第一次使用请修改本处数据库地址并相应修改data目录中数据库名称,如将.mdb修改

为.asp                           DB=Server.MapPath(DB)         
         'ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &Server.MapPath(db)
         Connstr="DBQ="+Db+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
          'Connstr="DBQ="+Server.Mappath(Db)+";DefaultDir=;DRIVER={Microsoft Access Driver

(*.mdb)};"
           '如果你的服务器采用较老版本Access驱动,请用下面连接方法
           'ConnStr="driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(db)           
    End If
    
    on error resume next
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.open ConnStr
    If Err Then
        debugError("ERR001")
        Err.Clear
        Set Conn = Nothing
        Response.End
    End If
End Sub

'打开数据链接
If Not IsObject(Conn) Then ConnectionDatabase
dim rs:set rs =server.createobject("adodb.recordset")


'========================================================
'输出错误提示
'当IsDeBug为true时,在打开数据库发生错误时会输入错误
'提示,否则不输入错误提示,建议在程序调试时打开,调试完后
'关闭该功能,
'========================================================

sub debugError(strErrCode)   
    if IsDeBug = 0 then
        for i = 0 to conn.errors.count-1        
            response.write "数据库连接出错,请检查连接字串<br>"
            response.write "<font style='font-size:10.5pt'><font color=red><b>Error Number

:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></font>" & conn.errors(i).number & "<br>"
            response.write "<font color=red><b>Error NativeError:&nbsp;</b></font>" &

conn.errors(i).nativeerror & "<br>"
            response.write "<font color=red><b>Error Source:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></font>" & conn.errors(i).source & "<br>"
            response.write "<font color=red><b>Error Description:&nbsp;</b></font>" &

conn.errors(i).description & "<br>"
            response.write "<!--Error Sql Code:" & strErrCode & "-->"
        next
    else
        response.write "正在系统维护,请稍后再试。<br>"    
        response.write
        response.end
    end if
    if conn.errors.count>0 then
        conn.errors.clear
         set conn=nothing
        '结束执行
        response.end
    end if
end sub

function depclassidconvert(theid)
  If IsSqlDataBase = 1 Then
   depclassidconvert=theid
  else
   depclassidconvert="'"&theid&"'"
  end if
end function

'关闭数据库连接
sub closedatabase
 Conn.close
 set Conn = Nothing
end sub

sub SortMenuInsearch
 dim rs2,sql2
 set rs2=server.createobject("adodb.recordset")
 sql2="select * from Class_1"
 rs2.open sql2,conn,1,1
 if rs2.eof and rs2.bof then
   response.write "<option value='没有类别'>没有类别</option>"
 else
  response.write "<option value='0'>所有类别</option>"&vbcrlf
 do while not rs2.eof
   response.write "<option value='"&rs2("SortID")&"'"
   if request("SortID")<>"" then
    if rs2("SortID")=clng(request("SortID")) then response.write " selected "
   end if
   response.write ">"&rs2("Sort")&"</option>"&vbcrlf
  rs2.movenext
 loop
 end if

 rs2.close
 set rs2=nothing
end sub


sub scripterr
  response.write"<script>alert('操作出错,下面是产生错误的可能原因:\n\n"&errstyle&"');history.go(-

1);</script>"
  response.end
end sub
%>
<!--#include file="./functions.asp"-->
<!--#include file="./adovbs.inc.asp"-->
<!--#include file="./configinfo.asp"-->
<%
dim ConfigInfo
set ConfigInfo=new GetConfigInfo_Class
ConfigInfo.load
%>
<%'...%>
搜索更多相关主题的帖子: 数据库 
2008-09-03 21:37
happynight
Rank: 8Rank: 8
等 级:贵宾
威 望:15
帖 子:807
专家分:760
注 册:2008-4-26
收藏
得分:0 
1.你确定你使用的数据库存在
2.确定数据库的路径,IP地址名称什么的没错
2008-09-03 22:35
tiankong118
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2008-8-27
收藏
得分:0 
数据库存在,是SQL的没错,路径也没有什么问题呀
2008-09-04 14:10
天上掉下的妹妹
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-9-4
收藏
得分:0 
看看是不是路径输入有问题.
2008-09-05 16:43
快速回复:这什么这个就连不上数据库
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015482 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved