Aug2008
18

SQL Server - Undocumented Stored Procedure sp_MSforeachtable

by nmgomes

I'm not an every day SQL Server user but I use SQL Server regularly since 7.0 version until the 2005 version (not yet tried 2008 in a serious way) and from time to time I still find some nice hidden gems.

A few days ago I needed to created a cleanup script for an application and one of the tasks was to drop all tables that match a specific name pattern.

My first thought was to use a cursor to loop or a dynamic SQL statement ...

... but this time I decided to google for some other approach, and I found the amazing undocumented sp_MSforeachtable stored procedure from the master database.

It does the same but it requires considerably less code and improves the script readability.

Below is the syntax for calling the sp_MSforeachtable SP: More...

Filed in: MS SQL

Aug2008
12

ASP.NET - Health Monitoring and EventLogWebEventProvider - Part 1

by nmgomes

The ASP.NET health monitoring enables you to add instrumentation to Web applications by using the so called Web Events. These Web events give us information about health status.

You can configure health monitoring by setting events and providers in the healthMonitoring section.

Naturally, ASP.NET provide us with a few out-of-the-box providers such as the EventLogWebEventProvider.

As many of you may have already notice, when using the EventLogWebEventProvider the events are added to the Application EventLog with the following source pattern:

        ASP.NET "framework version"

If you are using ASP.NET 2.0 the source will look similar to "ASP.NET 2.0.50727.0 ".

You can imagine what happen when a server hosts several web applications ... you can't easily figure which application raised a web event because you can't apply a filter to do that. To figure it out you must inspect the eventlog entry data.

If you think this is wrong and that Microsoft should do something about it, go here and here, vote and comment.

What can you do to overlap this? Well you can create your own EventLogWebEventProvider that allows you to specified which Source to use.

Doing such a provider is fairly simple but lead us to THE problem: which eventId to use when creating the EventLog entry?

What? Why is this a problem? are you saying.

Well, lets start all from the beginning ... you want to create your own provider so you can specify the EventLog source but you certainly desire to keep the remaining settings unchanged so that monitoring applications that track the EventLog entry for well known eventIds still working fine.

The problem is that Microsoft don't expose the algorithm used to created the eventId from the WebEvent data, and this way we can only guess which eventId to use.

If you look at EventLogWebEventProvider.ProcessEvent method you will find the following code:

int num = UnsafeNativeMethods.RaiseEventlogEvent((int) type, (string[]) dataFields.ToArray(typeof(string)), dataFields.Count); 

This is your black box, no source or information is available.

To guess which eventId is used for a specific Web Event I created a small page that raises all known Web  Events.

I found that even with all known Web Events configured to use EventLogWebEventProvider almost half of them don't appear in EventLog, but those that have an EventLog entry made me speculate that eventIds are sequential and follow the classes hierarchy. Here are the results:

Web Event EventLog entry eventId Speculated eventId range
WebBaseEvent - 1303
WebManagementEvent - 1304
WebApplicationLifetimeEvent 1305 1305
WebRequestEvent 1306 1306
WebHeartbeatEvent 1307 1307
WebBaseErrorEvent - 1308
WebRequestErrorEvent 1309 1309
WebErrorEvent 1310 1310
WebAuditEvent - 1311
WebSuccessAuditEvent 1312 1312
WebAuthenticationSuccessAuditEvent - 1313
WebFailureAuditEvent 1314 1314
WebAuthenticationFailureAuditEvent - 1315
WebViewStateFailureAuditEvent 1316 1316

 

Please note that I'm considering that no two different Web Events share the same eventId.

If you believe the assumptions made are correct you can now start coding your provider.

Remember that you must create the EventLog source before  use it. You can do this by using the EventLog.CreateEventSource method.

Filed in: ASP.NET

Aug2008
12

ASP.NET - EventMappingSettingsCollection bug on Contains method

by nmgomes

Recently, while digging on ASP.NET 2.0 Health Monitoring I found a bug in the EventMappingSettingsCollection.Contains class method.

I was trying to check if an event mapping already exists but every time I try it the following exception was thrown:

System.NullReferenceException was unhandled by user code
  Message="Object reference not set to an instance of an object."
  Source="System.Web"
  StackTrace:
       at System.Web.Configuration.EventMappingSettingsCollection.GetElementKey(ConfigurationElement element)
       at System.Configuration.ConfigurationElementCollection.GetElementKeyInternal(ConfigurationElement element)
       at System.Configuration.ConfigurationElementCollection.BaseIndexOf(ConfigurationElement element)
       at System.Web.Configuration.EventMappingSettingsCollection.IndexOf(String name)
       at System.Web.Configuration.EventMappingSettingsCollection.Contains(String name)

I opened a bug in connect, so, if you think this is important go there and vote.

And if you think this one is not a common error ... well ... this is the second bug I found regarding Contains method from a collection class.

Filed in: .NET | ASP.NET

Jul2008
16

BlogEngine.NET - BookShelf Widget

by nmgomes

In order to complete my migration from 1.3 to 1.4 version I needed to replace the books control I had with a widget that do the same.

After a fast Google search I found no widget with such functionality.

Armed with lots of confidence I decided to create a new widget, the BookShelf widget, to meet my exact needs:

  • display the book thumbnail image
  • show the book name and book author name

The previous book control has been gently made available by John Dyer, and I simply didn't worry about the layout, I used the old one with minor changes on binding.

books books_edit

This widget is obviously editable since I want to manage the books in the shelf, so I create an edit interface where its very simple to add, edit and remove books.

As a final note, I can simply reaffirm that work with widgets is very simple and straight forward.

Download, try it, and naturally let me now if it meet your needs too.

Filed in: BlogEngine.NET

Jul2008
13

BlogEngine.NET - Improved LinkList Widget

by nmgomes

I've been using BlogEngine.Net 1.4.0 since last week. It wasn't easy to migrate and keep the blog stable. To keep things working I made 3 updates (1.4.06, 1.4.0.8 and 1.4.0.12) in one week.

Finally on Friday I decided to update my theme to make use of widgets. This was my I first draw back ... my blog uses two sidebars and the BlogEngine.NET only suport ONE WidgetZone on the page.

I took almost the complete weekend to override this limitation and create an improved version of the widget framework that supports multiple WidgetZones.

I still have some issues to solve, such as the Drag'n'Drop of widgets, but all the rest is completely working and I currently using it on this blog. More on this will came soon.

After solve the WidgetZone issue I found out that the available widgets weren't enough to accomplished my needs, so, I decide to improve the LinkList widget.

I needed to:

  • add support for rendering the class attribute to the anchor Html elements (see the sidebar Meta section)
  • add support for rendering an HyperLink (see the sidebar My Profiles section)

I can only say that it was really simple to create or extend an widget.

I submitted this changes on LinkList widget as a patch on BlogEngine.Net (ID 1504), and perhaps Mads adds them in some future release.

Meanwhile you can get the code here

Filed in: BlogEngine.NET

Jul2008
1

NunoGomesControlToolkit - Improving Web Apps performance

by nmgomes

A few weeks ago I told you about a control toolkit I was making.

I decided to call him NunoGomesControlToolkit and is intended to improve web apps performance by decreasing total page size. This page size reduction is achieved by decreasing control ClientID size.

This control toolkit can be applied to any existing ASP.NET 2.0 Web Aplication by using the tagmapping configuration facility.

To obtain maximum redution it's also recommended to extend webforms, masterpages and usercontrols not from regular Page, MasterPage and UserControl controls from ASP.NET framework but instead use the corresponding control from NunoGomesControlToolkit.

TagMapping is only used for markup interpretation and therefore all dynamic created controls are not mapped. To override this limitation its also included in this toolkit the DynamicControlBuilder class. Use this class to allow tagmapping over dynamic created controls.

As I promise, the control toolkit is now available at code.msdn.microsoft.com.

I'm currently applying the NunoGomesControlToolkit to the BlogEngine.NET 1.3 version, and as soon as I test it I will make it available.

kick it on DotNetKicks.com

Filed in: ASP.NET

Jun2008
21

Is Maxtor messing with his costumers pocket?

by nmgomes

A few days ago, my aunt ask me to buy her an external portable hard drive for backups.

She's an accounting freelancer and works mainly in a laptop computer. To prevent loosing data she makes periodical accounting data backups.

I ask her to see the backup data size and is small ... very small, so ... I decide to buy her a small capacity 2,5´´ external hard drive.

Here is the chosen one: More...

Filed in: Hardware

Jun2008
18

ASP.NET Controls - Improving automatic ID generation : The ShortIDs Naming Provider (Part 4)

by nmgomes

In the previous posts on this subject I wrote about why automatic ID generation should be improved and how we can improve it. Now I will step forward and show you my own implementation of a specific naming provider.

As we saw in part 3, to create a specific Naming provider you only need to develop your own implementation of SetControlID method.

I named my naming provider ShortIDsProvider and it will have only one specification to meet:

  • it will create IDs in the form Txxx

where T denotes the 'T' character and xxx denotes an unique incremental integer value.More...

Filed in: ASP.NET