If no connection to server

  • Hello,

    Could someone please advise how I could place error checking in ASP if the SQL Database is not available and not stop the rest of the page from loading?

    I currently have a page that has some includes which do connect to not only different Databases, but also different SQL servers. I would like to know how to make it so if one of the Databases is down, then that particular include file states something like:

    We are currently unable to bring that information!

    (That is just an example)

    Then I want the rest of the site to load, rather than it just sitting there keeping the rest of the site down as other things may also be up and it keeps the site running and showing:

    As an example to have the wrong Username or Password on the DB I get the following:

    Microsoft OLE DB Provider for ODBC Drivers error '80040e4d'

    [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user '<DB  USER>'

    So if anyone could help in displaying an User Friendly error message rather than the nasty one that does come up, that would be great.

    Cheers,

    David

     

  • First I'd make sure that you have a custom 500-100 error page if you are using ASP. If you are using ASP.Net look at setting a custom error page in the web.config file. This is most important for security reasons. You don't want regular users of your website being able to read the internal error messages.

    As far as being more graceful, in C# ASP.NET you could place your connection.open() or command.execute() calls in TRY {} CATCH (SqlException e) {} blocks. That way you could trap the error and handle it gracefully. Same thing for JScript ASP.

    VBScript ASP however only give you that lovely ON ERROR RESUME NEXT functionality (thank MS for lack of foresight here). You'd need to check that the connection object is open (myconnection.status = 1 ?) , or check that the connection object has no errors (myconnection.errors.count = 0). You could also do this in JScript.


    Julian Kuiters
    juliankuiters.id.au

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply