本文介绍了修改代码,使datbase服务器不会崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何修改代码,以便在尝试访问数据库服务器时如果数据库服务器不可用,该代码不会崩溃?如果发生这种情况,那么必须有一种适当的方法来处理该错误.我不知道将Try..Catch过程放在哪里.

How do you modify code so that it will not crash if the database server is unavailable when you attempt to access it? If this happens then there must be an appropriate way to handle the error. I do not know where to put the Try..Catch procedure.



Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim db As New DBWrapper
        Dim l As ArrayList



        If Not IsPostBack Then
            Dim o As New Order
            o = Session("CurrentOrder")
            'Code so the program will not crash if the database server is unavailable when trying to access it.
            ' Try
            'Do something
            'Catch ex As Exception
            'Handle exception by displaying a message box
            'msgbox("Error happened because the database is not available" & ex.tostring())
            'Finally
            'dbwrapper.End
            ' End Try
            l = db.GetCustomersForLookup
            lstCustomer.DataSource = l

            lstCustomer.DataValueField = "Value"
            lstCustomer.DataTextField = "Description"
            lstCustomer.DataBind()


            If o Is Nothing Then

                calOrderDate.SelectedDate = Date.Today

            Else
                calOrderDate.SelectedDate = o.OrderDate


            End If

            SetFormToInitialState()
        End If


    End Sub

推荐答案

try
 <some code="" to="" use="" with="" database="">
catch (e as exception)
 <some code="" to="" do="" if="" above="" for="" example="">
 msgbox("Error happened at "+e.toString())
end try</some></some>


l = db.GetCustomersForLookup


这篇关于修改代码,使datbase服务器不会崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 18:45