Results 1 to 6 of 6

Thread: Complex DB connection failure handling

  1. #1

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Complex DB connection failure handling

    I'm connecting to a DB on a server. Sometimes connection closes due to some reasons that really aren't important here.

    I have some sort of a global error handling routine that is called from almost all error handlers.

    When performing simple procedures that are using the connection and ARE NOT calling any other procedures that also use it, there's no problem. Code breaks, error handling routine is called and everything is OK.

    But... when performing more complex procedures that are using the connection and are calling other procedures that also use it, sometimes code breaks in second level procedures (it depends when connection closes). My problem is that in this case first level procedures don't break. They continue working and everything goes just terribly wrong.

    I can think of some ways to fix this, but, are too complex since my project is... well, quite big.

    Any1?


  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Complex DB connection failure handling

    Could you cite a sample code that illustrates your case?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Complex DB connection failure handling

    Here's some pseudo code:
    Code:
    procedure1
    	code
    	procedure2 call
    	code (it should break here also, but it doesn't)
    procedure2
    	code
    	connection closes
    	code (breaks - OK)

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Complex DB connection failure handling

    Since procedure2 handles the error when it returns to procedure1 the error could have been cleared already. How about returning a boolean with procedure2 to determine if it has successfully done what it is supposed to do before letting procedure1 proceed?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Complex DB connection failure handling

    I'm using this approach in few cases but not all. Applying this to a complete project could take me few days. Also, most of the "procedure2" procedures are functions and already return other things in other types.

  6. #6
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Complex DB connection failure handling

    How about propagating back the error to the caller?

    Code:
    Private Sub Command1_Click()
        On Error GoTo Command1_Click_Err
        Test
    Exit Sub
    
    Command1_Click_Err:
        MsgBox Err.Description
    End Sub
    
    Private Sub Test()
        On Error GoTo ErrorHandler
        Err.Raise 100, , "test"
        Exit Sub
    ErrorHandler:
        MsgBox Err.Description
        Err.Raise Err.Number, Err.Source, Err.Description
    End Sub
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width