Popular Articles | Latest Articles | Categories | RSS Feeds

Error Loging in ASPNET

Published on 2/22/2005 by Site Editor
More articles in ASP.NET



 Vote this tutorial:

 

You may manage error handling configuring Web.Config file. In this code we will try to log this error page in to an SQL Server. This script will be helpful to webmaster to get a control over web pages.

Run this code to create table :

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[errorLog]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[errorLog]
GO

CREATE TABLE [dbo].[errorLog] (
 [errID] [int] IDENTITY (1, 1) NOT NULL ,
 [errorPage] [nvarchar] (150) ,
 [errorDate] [datetime] NULL
) ON [PRIMARY]
GO

Now we will create our stored procedure :

CREATE PROCEDURE dbo.insertLog
@page NVARCHAR(150)
AS
BEGIN
INSERT ErrorLog
( errorPage, errorDate )
VALUES
( @page, GETDATE() )
END
GO

Now if doed not exist web.config file create one or modify it  with those codes :



   
 
   

   
 
 
  />  
 

Ok. Our hard work finished after modifying our database connection. Double check that you have run sql scripts correctly without any error. You may use SQL Query Analyzer. Do not miss to check SQL connection. After editing and upload this script to your site.

<%@ Page Language="VB" Debug="true" %>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.SQLClient" %>
<%@ import namespace="System.Diagnostics" %>


Sub Page_Load(Source as Object, E as EventArgs)

 Dim objCon As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("strCon"))
 Dim objCmd As SqlCommand = New SqlCommand("insertLog", objCon)
 objCmd.CommandType = CommandType.StoredProcedure
 Dim strParm As SqlParameter = objCmd.Parameters.Add("@Page", SqlDbType.NVarChar, 150)
 strParm.Value = trim(request.querystring("aspxerrorpath"))
 objCon.Open()
 objCmd.ExecuteNonQuery()
 objCon.Close()
                       
end sub




 

Sorry, A error has occurred in this page.



 

 

You may check error table to find error pages. Automatically script inserts errors and gives you to repair errors.

Comments:
no comments submitted


Only members can write comments.Please, login / register to write comment.

Latest Posts

Active News Manager - news management system




Welcome to Dotnetindex.com:Login  |  Register
Free software:
Giga RSS Reader
IkonAdman
QMailing list
Active News
Download Manager (PRO)
Download Manager (Lite)

Search Dotnetindex.com:


Who's online

  • There 33 online users.

Latest tutorialsAutocomplete Filter from the Old Futures Project Working in Dynamic Data 4
Developing a Facebook Connect Application Using ASP.NET
Conditional Row Highlighting in Dynamic Data
UserControl as a DLL Made Easy
Using GroupTemplate in ASP.NET ListView Control (Tiled Display)
Creating Master-Detail GridView Using jQuery
ASP.NET MVC 2.0 and AJAX Part 1
Sorting Tabular Data in ASP.NET MVC
Asynchronous Form in ASP.NET MVC 2
Populating ASP.NET TreeView Control Recursively
A look at SAP Crystal Reports for Visual Studio 2010
Reporting in Threads
Regular Expressions Make Pattern Matching and Data Extraction Easier
Perform Database Administration Operations with SQL Server Management Objects
SQL Server Compact 3.5 Beta 2 available for download
ASP.NET Resources, Reviews

ASP Resources, Reviews

PHP, ASP, .NET, JSP Resources, Reviews

Hotscripts.com Free Photoshop, Flash and 3DS MAX tutorials