I have a website, where i want to use ASP error handling code like instr function which works as Java script.
I have two web pages, one have web forms and second one is database insertion.
I want to handle error code on runtime.
I have a website, where i want to use ASP error handling code like instr function which works as Java script.
I have two web pages, one have web forms and second one is database insertion.
I want to handle error code on runtime.
was trying to mix the VBScript InStr idea with JavaScript, and wanted runtime error handling for a form page and a separate DB-insert page. Classic ASP runs server-side (VBScript by default), so string helpers and error handling are different from client-side JavaScript. For server-side error trapping use VBScript patterns (On Error Resume Next + the Err object) or, if the page is written in server-side JScript, use try/catch. Protect the insert by validating input and using parameterized ADO commands so most SQL errors never happen.
A practical VBScript pattern: turn on On Error Resume Next only for the block you expect may fail, execute the DB command through an ADODB.Command with parameters, then immediately check Err.Number and ADO provider errors (conn.Errors) to log details. Clear the error, close objects, and restore default error handling with On Error GoTo 0.
<%
' server-side example (VBScript)
On Error Resume Next
Dim conn, cmd
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB;Data Source=YOURSERVER;Initial Catalog=YourDB;User ID=uid;Password=pw"
Set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = conn
cmd.CommandText = "INSERT INTO Users (Name,Email) VALUES (?,?)"
cmd.CommandType = 1
cmd.Parameters.Append cmd.CreateParameter(,200,1,50, Request.Form("name"))
cmd.Parameters.Append cmd.CreateParameter(,200,1,100, Request.Form("email"))
cmd.Execute
If Err.Number <> 0 Then
' log Err.Number and Err.Description
Dim e
For Each e In conn.Errors
' log e.Number & e.Description
Next
Err.Clear
End If
If Not conn Is Nothing Then conn.Close
Set cmd = Nothing
Set conn = Nothing
On Error GoTo 0
%> Troubleshooting notes: inspect Err.Number/Err.Description and loop conn.Errors for provider messages; write logs to a file under Server.MapPath or to the Windows Event Log rather than showing raw errors to users. Keep On Error Resume Next local (do not leave it on), validate inputs before DB work, and prefer parameterized ADODB.Command to avoid SQL syntax errors and injection. ’s request for the actual error is on point: the two items to capture for diagnostics are Err.Description and any entries in conn.Errors. Thanks to for pointing toward external guidance earlier.
Jump to Post— vsmash 14
i have a website, where i want to use asp error handling code like instr function which works as java script.
I have two web pages, one have web forms and second one is database insertion.
I want to handle error code on runtime.
can i have that error, so i try to find out the problem
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.