智能数据库链接

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Dim DBName(4)
DBName(4)="/Tsys/DataBase/DataBase.mdb"
DBName(1)="DataBase/DataBase.mdb"
DBName(2)="../DataBase/DataBase.mdb"
DBName(3)="../../DataBase/DataBase.mdb"
Dim DBName_Level
DBName_Level=0
Dim Connstr
Connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
Dim Conn
Set Conn=Server.CreateObject("ADODB.CONNECTION")
Call ConnOpen()

Function ConnOpen()
On Error Resume Next
Dim I
For I=1 To UBound(DBName)
Err.Clear
Conn.Open Connstr & Server.MapPath(DBName(I))
If Err.Number=0 Then
DBName_Level=I
ConnOpen=true
Exit Function
End If
Next
If DBName_Level=0 Then
Err.Clear
Response.Write "<p>以下数据库无法打开,请查看Conn.asp文件及*.mdb数据库的位置</p>"
For I=1 To UBound(DBName)
'打印所有数据库路径
'Response.Write("" & DBName(I) & "<br>")
Next
End If
End Function