Asp Adodb.connection Error Handling
Contents |
BLOG We didn't realize the site was so popular. Other Stuff How To Use On Error Resume Next Often when using asp on error ASP or Active Server Pages with VBScript you will find it necessary
Asp On Error Goto
to check for errors when you do certain things that may fail and then handle it accordingly. Things like opening adodb.connection errors a database connection or writing to a text file come to mind. Generally if an error is encountered in your .asp file, the processing of your script stops and an error ado error 2147467259 message is returned to the browser. If you want to continue processing your page even if an error is encountered, include the following line at the beginning of your .asp file: <% On Error Resume Next %> That being said just ignoring errors in your code is not a very good idea. What you really want to do is handle the error in some
Adodb Error Codes
way. The example below opens a database connection and shows you how to trap a potential error and do whatever you want because of it. In this case we are simply displaying the error. <% ConnectionString = "DBQ=c:\inetpub\wwwroot\mysite\data\mydatabase.mdb;Driver={Microsoft Access Driver (*.mdb)};" '*** This code checks the ConnectionString info you entered and reports back the error code if it is not ok Err.Clear On Error Resume Next Set ConnPasswords = Server.CreateObject("ADODB.Connection") ConnPasswords.Open ConnectionString If Err.Number <> 0 Then Response.Write (Err.Description& "
") Response.Write("This means there is most likely a problem with the" & vbCrLf) Response.Write("""ConnectionString"" info that you specified.
" & vbCrLf) Response.End End If On Error GoTo 0 %> We put the "On Error GoTo 0 at the end because that will essentially end the "on error resume next" That is something you want to do so any later errors in your application do not get ignored without you knowing about it. Below is another example. In this example our application logs user info in a text file when they sign in to a site. We add "On Error Resume Next" here sim
Portability Issues C++ & MFC » General Array Handling Binary Trees Bits and Bytes Buffer & Memory Manipulation Callbacks Classes and Class asp on error goto 0 Use Collections Compression Drag and Drop Events Exceptions External Links File asp error number I/O Function Calling Linked Lists Memory Tracking Object Oriented Programming (OOP) Open FAQ Parsing Patterns Pointers
Ado Connection Error Handling
Portability RTTI Serialization Singletons Standard Template Library (STL) Templates Tutorials Date & Time » General Date Controls Time Routines C++/CLI » .NET Framework Classes General ASP/ASP.NET http://www.powerasp.net/content/new/on-error-resume-next.asp Boxing and UnBoxing Components Garbage Collection and Finalizers Interop Moving from Unmanaged Processes & Threads Templates Visual Studio .NET 2003 String Programming » General CString Alternatives CString Extensions CString Manipulation Open FAQ Regular Expressions String Arrays String Conversions .NET COM-based Technologies » ATL & WTL Programming » General ATL Active Scripting ActiveX Controls http://www.codeguru.com/csharp/.net/net_general/debugginganderrorhandling/article.php/c19557/ASP-and-the-Error-Handler.htm Database Debugging External links Graphics Support Misc. Performance Printing Tutorials Utilities Windows Template Library (WTL) ActiveX Programming » General Active Scripting ActiveX Controls ActiveX Documents Apartments & Threading Error Handling External links General COM/DCOM Misc. Registry Security Structured Storage Tutorials Wrappers COM+ » General COM Interop Managed Code / .NET SOAP and Web Services Shell Programming » General Open FAQ Shortcuts Tray Icons Previous Section Manager Controls » Property Sheet » Open FAQ Property Sheet Buttons Sizing Wizards Button Control » Advanced Buttons Bitmap Buttons Flat Buttons Menus Non-Rectangular buttons Windows XP ComboBox » Colour Pickers DropDown Font selection combos Multicolumn combos Special Effects Tooltips Edit Control » Background & Color Editors Keyboard Masked Edit Controls Passwords and Security Spin Controls Transparent ImageList Control » Open FAQ ListBox Control » Checkboxes Color Listboxes Drag & Drop LEDs ListView Control » Advanced Background color and image Checkboxes Columns Custom Drawing Data Deleting Drag & Drop Editing items and sub
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site http://stackoverflow.com/questions/19799181/using-custom-error-message-in-classic-asp-when-database-connection-is-down About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Using Custom Error Message on error in Classic ASP when Database connection is down up vote 0 down vote favorite We have a site that is running IIS 6 and ASP classic. We connect to an Oracle database to gather information to display on this web-page. When the database is down the end-users see a typical asp error message about being unable to connect to the database. I would like to asp on error display a custom error message that would read something like "The database is currently unavailable at this time". Can anyone provide the syntax in ASP using an oracle connection string to accomplish this? Thanks. oracle asp-classic error-handling database-connection share|improve this question asked Nov 5 '13 at 21:18 user2167563 11 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote This is what I use; On Error Resume Next Set con = Server.CreateObject( "ADODB.Connection" ) con.Open "Provider=myOracleProvider;Data Source=myOracleDB;User Id=myUsername;Password=myPassword;" If Err.Number = 0 And con.Errors.Count = 0 Then 'No problems connecting to DB so don't do anything ELSE 'Problems connecting to DB so do something to handle this or alert adm END IF On Error goto 0 Obviously adapt the connection string to suit your specific Oracle environment and database credentials. share|improve this answer answered Nov 6 '13 at 11:12 Andy Davies 1,186714 add a comment| up vote 0 down vote There is a try catch like syntax in classic asp. use an on error resume next. Please read more aout this at Try-Catch-End Try in VBScript. Then you can reset the error status to 0 just before the db