试试。测试通过后自己去掉调试代码,如果不通,把调试结果发上来看看
Dim ipFile As String = e.ProjectPath & "ip.txt"
If e.Name = "foxtable人事数据库" OrElse e.name = "foxtable" OrElse e.name = "mirror" Then
MsgBox("数据源=" & e.Name)
Dim ip As String
Dim lst As New List(Of String)
lst.AddRange({"", "192.168.0.150", "192.168.1.150", "192.168.111.150"})
If Filesys.FileExists(ipFile) Then
ip = FileSys.ReadAllText(ipFile)
lst(0) = ip
MsgBox("文件记录的是" & ip)
End If
Dim cs As String = e.ConnectionString
For Each s As String In lst
If s > "" Then
Dim s1 As String = cs.Replace("192.168.0.150", s)
MsgBox("测试连接:" & s)
If Connections.TryConnect(s1) Then
e.ConnectionString = s1
filesys.WriteAllText(e.projectpath & "ip.txt", s, False)
MsgBox("连接成功:" & s)
Exit For
End If
End If
Next
End If