locked
Exception Handling for Database Connection Problems RRS feed

  • Question

  • User-574293449 posted

    Hi,

     I created a REST service which have exception handling using IErrorHandler. Now i can log in Handle Error event. But my requirement is to log all the errors even user error in the database table. I am throwing user exception as ApplicationException so i can handle this using one insert method in DAL.\

    But i am confused how to handle or check the specific connection errors like sql login  failed, server down or network related issues, provider mismatch etc. Can you give a best practice for this exceptions.

    My thinking is to just avoid logging so that errors goes to user. But how to check these type of specific errors

    Monday, February 10, 2014 9:27 PM

Answers

  • User-417640953 posted

    So all errors i can log here. But when even the connection problem i need to skip this because we can't log if there is connection problem. So i need to check whether the error is connection related error.

    Hi,

    Thanks for your response.

    For this issue, I think we can log this type error message to some temple file such as txt file which saved in your application folder.

    Then save this data from temple file to database when the sql connection working.

    There are SqlException Class you can refer to.

    http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlexception(v=vs.110).aspx

    Hope this helps, thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 13, 2014 8:28 PM

All replies

  • User-417640953 posted

    But i am confused how to handle or check the specific connection errors like sql login  failed, server down or network related issues, provider mismatch etc. Can you give a best practice for this exceptions.

    Hi akhilrajau,

    Thank you post the issue to asp.net forum.

    With your description, I see that you want to catch the unhandler exception and save the error information to database.

    even the sql login  failed, server down or network related issues.

    For this issue, I suggest you using Enterprise Library to Log Warning and Exceptions to database.

    And you can call the EL from the IErrorHandler.

    Besides, I also would like to suggest you take a minute to look at below article Fault Handling in WCF Services.

    http://msdn.microsoft.com/en-us/library/ee942778.aspx

    Hope that helps, thanks.

    Best Regards!

     

    Thursday, February 13, 2014 3:38 AM
  • User-574293449 posted

    Thanksd for the ressponse Fuxiang. Sorry we are not using Enterprise Library now. Surly will check this.

    Actually i am logging the errors to my application thorugh Handle Error event of IErrorHandler. So all errors i can log here. But when even the connection problem i need to skip this because we can't log if there is connection problem. So i need to check whether the error is connection related error.

    Also if the network failed or sql Service is not running how can i capture the exceptio. These types not thwoing excweptions. May i handle IIS errors for this?

     

    Thursday, February 13, 2014 4:11 AM
  • User-417640953 posted

    So all errors i can log here. But when even the connection problem i need to skip this because we can't log if there is connection problem. So i need to check whether the error is connection related error.

    Hi,

    Thanks for your response.

    For this issue, I think we can log this type error message to some temple file such as txt file which saved in your application folder.

    Then save this data from temple file to database when the sql connection working.

    There are SqlException Class you can refer to.

    http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlexception(v=vs.110).aspx

    Hope this helps, thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 13, 2014 8:28 PM
  • User-574293449 posted

    Thanks. Even i check for SQLException i need to verify the exact error numbers for the connection problems. Am i right?

    Actually i wrapped the handle error event with try..catch and throw the unhandled exception in the catch. But it cause the Just In Time errors. So i used try..catch but in the catch i just use return false with out thwoing any errors.

    I don't know is this good approach. But this approach helped me to solve the issue. But please give the correct approach or is this a good practice for this scenario?

    Thursday, February 13, 2014 10:42 PM