SQL Profiler templates missing

Uncategorized No Comments

If you are connecting to a SQL server with the SQL profiler and none of your templates are showing up, check the version of the SQL server you are connecting to, compare the versions of the SQL profiler you are running and the SQL server you’re connecting to; there is likely a version mismatch.

What’s happening here is that you’re connecting to a SQL 10.50 instance with a SQL 10.0 profiler and the profile templates for 10.50 aren’t present.

In the case of the profiler from SQL 2008 connecting to a SQL 2008 R2 instance, copy your 100 profile templates folder (default install is at C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Profiler\Templates\Microsoft SQL Server\100) into a new folder in the same location with the name “1050″ i.e. C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Profiler\Templates\Microsoft SQL Server\1050.

Then try to reconnect, and you’ll have access to the profile templates and everything will work fine.

More information about SQL versions can be found at: http://sqlserverbuilds.blogspot.com/

Loading jQuery via HTTP or HTTPS depending on the request protocol without document.write

Uncategorized No Comments

When running a page with HTTPS, you’ll want to also load any external resources such as javascript via HTTPS. A lot of people recommend loading jQuery from the Google CDN via the following javascript script:

<script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://" : "http://");
    document.write(unescape("%3Cscript src='" + gaJsHost + "ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js' type='text/javascript'%3E%3C/script%3E"));
    document.write(unescape("%3Cscript src='" + gaJsHost + "ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js' type='text/javascript'%3E%3C/script%3E"));
    document.write(unescape("%3Cscript src='" + gaJsHost + "ajax.googleapis.com/ajax/libs/swfobject/2.1/swfobject.js' type='text/javascript'%3E%3C/script%3E"));
</script>

This works just fine, however you can let the browser select the protocol depending on the request by the following snippet:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/swfobject/2.1/swfobject.js"></script>

This is obviously much cleaner, and you can see the full URL rather than javascript code to build up a string. The key here is the double slash within the src attribute. This kind of url works for any web resource and is particularly useful for loading resources from the Google CDN.

How to include the Fluent NHibernate discriminator column in a composite key

Development No Comments

In our project, we’re sub classing multiple domain classes from a single Reference Data table – i.e. Volume and Weight types. Among other things, the reference data table contains discriminator, code and value columns. The ‘discriminator’ column stores the name of the class and is used by Fluent NHibernate to determine which subclass to instantiate, the ‘value’ column is the full name of the reference data item, and the ‘code’ column is the abbreviated version of the value.

The code and value together are unique, and a composite key is created containing them both.

We load in reference data from an excel spreadsheet, and at some point, there was a code and value pair added to a reference data type which matched exactly with a code and value pair from another reference data type. Attempting to add the second code value pair resulted in a unique key violation.

I needed to add the discriminator column into the composite key. If you’re using auto mapping, you’ll need to add an auto mapping override. Below is an example of creating a composite key containing the code, discriminator and value columns.

 public class ReferenceDataAutoMappingOverride : IAutoMappingOverride<ReferenceData>
 {
 public void Override(AutoMapping<ReferenceData> mapping)
 {
 const string uniqueKeyName = "UK_ReferenceData_discriminator_Code_Value";
 mapping.DiscriminateSubClassesOnColumn<string>("discriminator").UniqueKey(uniqueKeyName);
 mapping.Map(refData => refData.Code).UniqueKey(uniqueKeyName);
 mapping.Map(refData => refData.Value).UniqueKey(uniqueKeyName);
 }
 }

ASP.NET MVC – Multiple parameterised form submit buttons without Javascript

Development No Comments

The current project I’m working on involves a search page with multiple submit buttons in a single HTML form. Each submit button triggers a different behavior while posting all of the form data to the controller.

This method is compatible with both IE 6+ and Firefox. It also avoids the IE button bug where button values are not passed on HTTP POST.

After discussing a few design options we decided to allow the user to add the desired search parameters via selecting them one by one from a drop down list. The user will commonly want up to three parameters at a time and may want to remove parameters after adding.

The relevant basic requirements of the search page were as follows:

  • The form must work with JavaScript turned off
  • 26 optional parameters.
  • Display only the active parameters on screen.
  • The user must be able to add/remove parameters to/from the screen.
  • The user must be able to select individual items from the search results and download full XML certificate data for the selected records.
  • The user must be able to export all search results to a CSV file for processing in Excel.

Buttons on forms allow us to go through a single action on the controller, we’ll call this PerformAction.

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult PerformAction(HomeModel model, ButtonActionModel buttonAction)
{
	model.Items.Where(x => x.Key == buttonAction.ActionValue);
	if (buttonAction.ActionName == ButtonActionNames.Remove.ToString())
	{
		RemoveItem(buttonAction.ActionValue, model);
	}
	TempModel = model;
	// Post-get-redirect pattern:
	// http://blog.jorritsalverda.nl/2010/03/10/maintainable-mvc-post-redirect-get-pattern/
	return RedirectToAction(ViewNames.Index, null);
}

PerformAction accepts two parameters; HomeModel contains all of the form data and ButtonActionModel contains the button parameter data.

public class ButtonActionModel
{
	public string ActionName { get; set; }
	public string ActionValue { get; set; }
}

The button model contains the name of the action (i.e. “Remove”) and the value of the action (i.e. “Parameter1″). The names and values are arbitrary and can be handled however you like in the PerformAction method.

In HTML, the buttons look like:

<input name="buttonaction:Remove:Parameter1" type="submit"
       value="Remove Parameter 1"></input>

We’ll need a custom model binder to create the ButtonAction model.

public class ButtonActionBinder : DefaultModelBinder
{
	public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
	{
		var request = controllerContext.HttpContext.Request;
		var formKeys = request.Form.AllKeys;
		ButtonActionModel result = null;
		var indexedbutton = formKeys.Where(x => x.StartsWith("buttonaction")).FirstOrDefault();
		if (indexedbutton != null)
		{
			result = new ButtonActionModel();
			var split = indexedbutton.Split(':');
			result.ActionName = split[1];
			if (split.Length > 2) result.ActionValue = split[2];
		}
		return result;
	}
}

The model binder above is fairly simple, searching the submitted form data for “buttonaction” which is the first part of the button name.

The binder then splits the button name based on the colons, using the second element as the ActionName and the third element as the ActionValue. Once this is done, the binding is complete and the bound model is returned.

Add the model binder to Application_Start in Global.asax.cs

ModelBinders.Binders.Add(typeof(ButtonActionModel),
                         new ButtonActionBinder());

Here’s an extended example demonstrating multiple parameterised form submit buttons without Javascript: MvcMultiSubmit

Installing Sketchables for Sketchflow

Design No Comments

We used to use Balsamiq for mockups, however Expression Blend 4 and Sketchflow has some compelling features.

Sketchflow is missing a sketch style grid among other things, so we looked to Sketchables to provide.

Referencing Sketchables.Silverlight.dll wasn’t enough, the new controls weren’t appearing in the “Assets” panel. Initially I tried referencing the designer files, but that yielded no results. Reading the blog comments from hardcodet.net there was the following one-liner:

The libraries in the “design” folder are automatically picked up. They are used in Blend in order to provide the design time support.

The “Design” folder must sit below the folder which contains the referenced Sketchables.Silverlight.dll; Expression Blend 4 silently scans dlls in the design folder and loads them into the Assets panel.

Bitbucket – wrong user on commit

Development No Comments

I was having an issue where after pushing my changes to bitbucket, the changesets listed a different user as having pushed the files.

For bitbucket, the commit username has to match your bitbucket username.

As commits in Mercurial are local, we have no way of controlling that you have set your username correctly. It is important for you to set this up in such a way that we can identify your user account on Bitbucket when you push your commits to us.

In tortoise-hg, the username setting is available through global settings->commit

Hello world!

Uncategorized No Comments

Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!

Icons by N.Design Studio. Designed By Ben Swift, modified by Matt Button. Powered by WordPress, and Free WordPress Themes
Entries RSS Comments RSS Log in

Page optimized by WP Minify WordPress Plugin