【发布时间】:2023-03-21 14:15:02
【问题描述】:
我的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
但是当连接不可用时,会抛出异常。
如何通过给一个类似connection not available at the moment, please try again later 的消息框来避免异常,然后退出正在使用该函数的子程序?
结束子
【问题讨论】:
-
这是 OpenMysqlCon,我已经更正了错字,对不起朋友。
标签: mysql vb.net mysqlconnection