Archive for June, 2008

Google like autocomplete suggestions

June 11, 2008

I like Google’s suggest feature and was thinking of using it in any of my project. ASP.NET’s AJAX Control Toolkit have a similar control (AutoCompleteExtender) which provides a basic items to complete this functionality. I searched about its usage, and found many examples, but I was not satisfied with them. They all were populating only a single field using this extender.

I then came up with an idea, why not fill a contacts detail including its name, email address, and phone numbers using just one extender, but without modifying any provided functionality, so that our code be used with newer versions. Below is what it will look after populating that contact form.

(more…)

Rollover logging in database

June 3, 2008

We are currently working on an application (window service), which grabs alerts data from a third party web application and parses each alert and process its status, reasons, and source for different attributes and then creates tickets for support staff.

In this project we were logging all detail activities of parsing alerts into our database, which alert was raised, what was the source and ip address and so on. Our service was grabbing data from that website after five minutes interval. There were nearly hundreds of alerts on each pass. So our log table was getting heavy each day.

We decided to implement rollover logging into this, so that previous logs could be discarded if not required. So we came up with following solution. In it we move yesterday’s log entries to a new table, and truncated current log table.

ALTER PROCEDURE [dbo].[LogEntry]
(
    @AlertID AS int,
    @Message AS varchar(1000)
)
AS

DECLARE @TableName AS nvarchar(200),
        @CurrentDate AS datetime,
        @PreviousDate AS datetime

SELECT
    @PreviousDate = getdate()-1,
    @CurrentDate = getdate()

SELECT
    @TableName = 'Logs_' + CONVERT(varchar, @PreviousDate, 112)

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(@TableName) AND type IN (N'U' ) )
BEGIN
    EXEC ( 'SELECT * INTO ' + @TableName + ' FROM Logs' )
    TRUNCATE TABLE Logs
END 

INSERT INTO Logs
(
    AlertID,
    [Message],
    EntryDate
)
VALUES
(
    @AlertID,
    @Message,
    GETDATE()
)