以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  为什么无法修改连接字符串?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=145488)

--  作者:sloyy
--  发布时间:2020/1/22 14:19:00
--  为什么无法修改连接字符串?
我在BeforeConnectOuterDataSource事件里写了如下代码:
If e.Name = "zbxt" Then
    If Network.Ping("www.163.com",1000) = False  Then \'如果网易无法接通
        e.ConnectionString = e.ConnectionString.Replace("110.20.199.135", "192.168.2.27")
    End If
End If

结果在外网运行正常,在内网无法切换到192.168.2.27

哪里出问题了?
[此贴子已经被作者于2020/1/22 14:19:26编辑过]

--  作者:有点蓝
--  发布时间:2020/1/22 14:33:00
--  
参考:http://www.foxtable.com/webhelp/topics/2709.htm,如果断网,ping是会出错的,导致后面的代码不执行。如果没有断网,ping肯定是通的,也不会执行后面的代码。所以这种用法仅支持局域网没有外网连接的情况

If e.Name = "zbxt" Then
    If TryConnectHost("www.163.com")=False  Then \'如果网易无法接通
        e.ConnectionString = e.ConnectionString.Replace("110.20.199.135", "192.168.2.27")
    End If
End If

--  作者:sloyy
--  发布时间:2020/1/22 14:56:00
--  
谢谢有点蓝大师,确实如此.
改用:TryConnectHost("www.163.com") 
问题顺利解决,内外网切换无障碍了.