我有这段代码
Me.WebDetailsByIDTableAdapter.FillbyID(Me.WebDataSet.WebDetailsByID, CType(Me.WebRefSpinEdit.Text, Integer))
在Try / Catch Block中。
TableAdapter是从互联网数据库填充的。我们的服务提供商拥有动态IP地址。因此,我们必须定期登录数据库控制面板以允许从我们的IP进行访问。
当我在调试模式下运行代码时,收到以下错误:
抛出异常:MySql.Data.dll中的'MySql.Data.MySqlClient.MySqlException'
其他信息:使用方法'mysql_native_password'对用户'###'进行主机'####'身份验证失败,并显示消息:用户'#'拒绝访问数据库'###'
try catch块是:
Private Sub frmCourse_Details_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim con As New MySqlConnection(My.Settings.WebConString)
Try
Me.BodiesTableAdapter.Fill(Me.MainDataSet.Bodies)
Me.ListCompaniesTableAdapter.Fill(Me.MainDataSet.ListCompanies)
Me.StatusTableAdapter.Fill(Me.MainDataSet.Status)
Me.CourseLIstTableAdapter.FillCoursesList(Me.MainDataSet.CourseLIst)
Me.CourseDocumentsTableAdapter.Fill(Me.MainDataSet.CourseDocuments, Me.CourseTextEdit.GetColumnValue("ID"))
If String.IsNullOrEmpty(Me.DateofCourseDateEdit1.Text) Then
Me.barFolderStatus.Caption = "Folder Not FOUND"
Else
Dim d As Date = Me.DateofCourseDateEdit1.Text
System.IO.Directory.CreateDirectory(GetCourseDirectory(CSEID))
If System.IO.Directory.Exists(GetCourseDirectory(CSEID)) Then
Me.barFolderStatus.Caption = GetCourseDirectory(CSEID) & " - Folder OK!"
Else
System.IO.Directory.CreateDirectory(GetCourseDirectory(CSEID))
Me.barFolderStatus.Caption = "Folder Not FOUND"
End If
End If
Me.RolesTableAdapter.Fill(Me.MainDataSet.Roles)
Me.InstructorsByCourseTableAdapter.Fill(Me.MainDataSet.InstructorsByCourse, Me.CourseTextEdit.Text)
If Me.CourseTypeTextEdit.Text = "Internal" And Not String.IsNullOrEmpty(Me.WebRefSpinEdit.Text) Then
Me.WebDetailsByIDTableAdapter.FillbyID(Me.WebDataSet.WebDetailsByID, CType(Me.WebRefSpinEdit.Text, Integer))
End If
Me.InstsGrid.RefreshData()
con.Open()
If con.State = ConnectionState.Open Then
BarStaticItem1.Caption = "Website Access OK"
Else
BarStaticItem1.Caption = "No Website Access"
End If
InitialSetDetails()
UpdateRibbon()
Me.Cursor = Cursors.Default
Catch ex As Exception
MessageBox.Show("Load Course Details:" & ex.Message)
Finally
con.Dispose()
End Try
Me.IDSpinEdit.ReadOnly = True
End Sub
为什么没有捕获此异常?我应该实现一些其他错误处理代码吗?