小弟经常连接局域网数据库,但是有时候经常网络会连接不上,如何处理才能让程序不自动退出,请高手解答
If (cn.State = 0) Then
cn.ConnectionString = "Provider=SQLOLEDB.1;Password=22222;Persist Security Info=False;User ID=sa;Initial Catalog=lyzj1;Data Source=192.168.0.3,14333"
cn.Open '加载表,排列出会员信息
rs.CursorLocation = adUseClient
rs.ActiveConnection = cn
rs.CursorType = adOpenKeyset
rs.LockType = adLockPessimistic
End If
If (cn.State = 0) Then
cn.ConnectionString = "Provider=SQLOLEDB.1;Password=22222;Persist Security Info=False;User ID=sa;Initial Catalog=lyzj1;Data Source=192.168.0.3,14333"
cn.Open '加载表,排列出会员信息
rs.CursorLocation = adUseClient
rs.ActiveConnection = cn
rs.CursorType = adOpenKeyset
rs.LockType = adLockPessimistic
End If
private sub command1_click()
on error goto ErrHandle:
If (cn.State = 0) Then
cn.ConnectionString = "Provider=SQLOLEDB.1;Password=22222;Persist Security Info=False;User ID=sa;Initial Catalog=lyzj1;Data Source=192.168.0.3,14333"
cn.Open '加载表,排列出会员信息
rs.CursorLocation = adUseClient
rs.ActiveConnection = cn
rs.CursorType = adOpenKeyset
rs.LockType = adLockPessimistic
End If
exit sub
'错误处理:
ErrHandle:
msgbox "连接失败,错误原因为:" & err.description,vbexclamation,"提示"
exit sub
end sub