Monday, March 26, 2007

The coolest log parser

Once again Microsoft has come up with an awesome and very smart utility called Log Parser. It uses SQL-like syntax to allow you to query many kinds of sources. Example sources are web logs from IIS, EventLog in Windows, Active Directory, LDAP, etc. Here is how I got hits on a specific page in my application by month: LogParser "SELECT TO_STRING(date, 'yyyy-MM') as MONTH, COUNT(*) AS Hits FROM <FrontLine> where cs-uri-stem = '/KnowledgeBase.aspx' GROUP BY TO_STRING(date, 'yyyy-MM'), cs-uri-stem ORDER BY TO_STRING(date, 'yyyy-MM') DESC" In case that wasn't cool enough, you can output results to a chart (file), Database, Excel, etc. Here is where you can get the latest binary from: Here is a good example for web logs usage: Here is how to use it from C#: This seems to be a good tutorial:

Wednesday, March 14, 2007

Waiting in SQL 2005

Have you ever needed to wait in a stored procedure? Well here is how. Declare @Counter as int

Set @Counter = 0 while @Counter < 3 BEGIN print @Counter Set @Counter = @Counter + 1 WAITFOR DELAY '00:00:02' -- waits for 2 seconds before next line is executed. END

Thursday, March 8, 2007

ASP.Net Custom Server Control Lessons

When writing a custom server control in ASP.Net it is pretty straight forward. It is common to put the output of the control right in the Render() method. Be aware this is very late in the control and page lifecycle. What that means if you try to modify the value of another control on the page it will appear to work in code, but the changes will not be shown in the browser. The reason is that the page is being rendered, it is too late to change .net server control values. So, it is easy to do put the "render" code in OnLoad(). Here is an example.

protected override void OnLoad(EventArgs e) { // do "rendering here" if you need to change values on the page i.e. raising an event ControlOutput = "<span>Hi</span>"; } protected override void Render(HtmlTextWriter output) { output.Write(ControlOutput); }

If you want to reproduce something link a LinkButton you will need to implement IPostBackEventHandler. This works in conjunction with __doPostBack() method.

Page.ClientScript.GetPostBackEventReference(this, "MyActionNameHere"). To learn more about this, check out the ASP.Net QuickStart