devxlogo

Check for Errors While Connecting to a Database

Check for Errors While Connecting to a Database

When connecting to a database, you should check for errors and return a descriptive user-friendly error message. This code calls an error handler routine after connecting to the database. If an error occurs, an email is sent to inform someone (usually server admin) that an error occurred, what the error description is, and the name of the Web page. The error routine can be used as an include file.

  0 Then		varEmailMsg = "The following error has _occurred: "& "
Error Number: _" & varError & "" & _ "
Error Message: _" & varDesc & "" varMsg = "_An error has occurred while connecting tothe database.

An email has been sent to the Help Desk.

" Response.Write varMsg'--------------------------------------------------'-- Send an email to the Help Desk and Server Group'-------------------------------------------------- Dim strTo, strSubject, strBody Dim objCDOMail strTo = "[email protected]; [email protected]" strSubject = "Database Connection Error" strbody = varEmailMsg & _"

Connection String: " _& varConnection& "
File Name: " & _varFileName & "" Set objCDOMail = _Server.CreateObject("CDONTS.NewMail") objCDOMail.From = "Name " objCDOMail.To = strTo objCDOMail.Subject = strSubject objCDOMail.Body = strBody objCDOMail.BodyFormat = 0 ' CdoBodyFormatHTML 'Outlook gives you grief unless you also set: objCDOMail.MailFormat = 0 ' CdoMailFormatMime objCDOMail.Send Set objCDOMail = Nothing End IfEnd Sub%>

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist