有这样一个按键代码和这样一个表:
Dim drs As List(Of DataRow)
drs = DataTables("数据源设置").Select("[软件名称] is not null")
For Each dr As DataRow In drs
If Connections.Contains(dr("软件名称")) Then
Connections.Delete(dr("软件名称"))
End If
If dr("数据库类型") = "SQL server" Then
Dim s As String = "Provider=SQLOLEDB.1;Password=" & dr("用户密码") & ";Persist Security Info=True;User ID=" & dr("用户名") & ";Initial Catalog=" & dr("数据库名") & ";Data Source=" & dr("数据库地址")
Connections.Add(dr("软件名称"),s)
If Connections.TryConnect(s) = False Then
MessageBox.Show("数据源" & dr("软件名称") & "无法连通!")
Else MessageBox.Show("数据源" & dr("软件名称") & "已连通!")
dr("连接") = True
End If
End If
Next
此主题相关图片如下:未命名.bmp

我的意思是想通过按键动态连接数据源,各种设置在表里面。
可以反复连接的,因为有个删除代码在里面。
但是如果反复了很多次后,狐表就可能会死。重启狐表也不行。
重启电脑后又正常了。
请各位看看是不是代码有问题?