Nov 1

数据库连接文件写法 晴

碟舞飞扬 , 20:26 , Web开发 , 评论(0) , 引用(0) , 阅读(3855) , Via 本站原创 | |
<%Dim StartTime,SQLQueryNums,opensql,errmsg
StartTime=Timer()
SQLQueryNums=0
opensql=1
errmsg="<head><meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"" /><title>数据库连接出错,请检查连接字串</title></head><body><div align=""center"" style=""width:400px;height:100px;padding: 8px;font-size:9pt;border: 1px solid ThreeDShadow;POSITION:absolute;top:expression((document.body.offsetHeight-100)/2);left:expression((document.body.offsetWidth-400)/2);""  valign=""top""><table width=""100%"" height=""100%"" style=""font-size:12px;font-family:Tahoma;""  valign=""top""><tr><td align=""center"" valign=""top""><strong>数据库连接出错,请检查连接字串</strong></td></tr></table></div></body>"
'定义数据库链接文件,根据自己的情况修改
Const AccessPath="1212"
Const AccessFile="#1212.mdb"

'定义数据库连接
if opensql=0 then
     Dim Conn
     On Error Resume Next
     Set Conn= Server.CreateObject("ADODB.Connection")
     Conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(AccessPath&"/"&AccessFile)
     Conn.Open
    If Err Then
      Err.Clear
      Set Conn = Nothing
      Response.Write(""&errmsg&"")
      Response.End
  End If
else'sql数据库连接参数
    Dim SqlDatabaseName,SqlPassword,SqlUsername,SqlSource,Driver
        SqlDatabaseName = "21321"    '数据库名    
        SqlUsername = "sa"            '用户名
        SqlPassword = "admfin"        '用户密码
        SqlSource = "(local)"        '数据地址(本地用local,远程用IP)
        Driver = "Provider = Sqloledb; User ID = " & SqlUsername & "; Password = " & SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source = " & SqlSource & ";"
       On Error Resume Next
       set Conn = server.CreateObject("ADODB.Connection")
       Conn.open Driver
       If Err Then
        err.Clear
        Set Conn = Nothing
        Response.Write(""&errmsg&"")
        Response.End
       End If
end if%>
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]