网页编程 - ASP连接主数据库,如果失败则连接备用数据库
On Error Resume Next
'连接到主数据库
conn.open "provider=sqloledb;data source=XXXXXXXX,1433;User ID=sa;pwd=XXXXXXXXXX;Initial Catalog=XXXXXXXXX"
If conn.State = 0 Then
conn.close
'如果主数据库连接失败,则连接到备用数据库
conn.open "provider=sqloledb;data source=localhost,1433;User ID=sa;pwd=XXXXXXXXX;Initial Catalog=XXXXXXXXX"
if conn.state = 0 then
Set Conn=Nothing
'如果备用数据库也连接失败,则显示连接失败信息
Response.write "<div style='margin:150px auto;width:100%;text-align:center;font-size:2.5em;'>无法连接远程服务器!</div>"
Response.End
end if
End If
On Error Goto 0