我有這方面的功能在我的VB.NET工程VB.NET函數返回錯誤並退出子
Public Function OpenMysqlCon() As MySqlConnection
Dim mMysqlconnection = New MySqlConnection()
Try
Dim strconDB As String = "server='192.168.100.2'; database='mydb';Port=3306; UID='epb'; password='hahaha'; pooling=true"
mMysqlconnection = New MySqlConnection
mMysqlconnection.ConnectionString = strconDB
mMysqlconnection.Open()
OpenMysqlCon = mMysqlconnection
Catch exceptionThatICaught As System.Exception
OpenMysqlCon = Nothing
End Try
End Function
,我會調用該函數在我的VB項目類似
Private Sub frmTest_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Using Con=OpenMysqlCon()
'mycode here
End Using
End Sub
然而當連接不可用時,它會拋出異常。
我如何通過給msgbox類似connection not available at the moment, please try again later
的東西來避免異常,然後退出使用該函數的子?
End Sub
它是OpenMysqlCon,我修正了錯字,對不起朋友。 –