0

我在 vb.net 中编写了一个程序,它使用 comm 端口传递数据,保存在 Access 2010 数据库中,然后将该数据传输到 SQL 服务器。该程序需要一年 365 天,每天 24 小时运行。如果服务器出现故障或网络断开,它仍然需要在本地运行和保存数据。

所以这就是我遇到的问题。当我执行程序并拔下网线时,我显然会收到错误消息,但我需要错误消息不中断程序,我只想要一个弹出框。

任何帮助将不胜感激。我不确定要发布什么代码,看看有这么多。

4

2 回答 2

1

您应该将 Try...Catch...Finally 语句添加到您的 vb.net 代码中以捕获和处理异常。

http://msdn.microsoft.com/en-us/library/fk6t46tz(v=vs.71).aspx

于 2013-07-17T15:41:34.253 回答
1

使用 try 语句,这将是最简单的方法。

Try

'run what ever code you need here

Catch ex As Exception

'when your network goes down the function that is called to interact with the web will trigger this.
'so you can save your stuff at this part

Finally

'after everything is done you can do what ever you want here.

End Try
于 2013-07-17T15:45:38.413 回答