Latest Blog Posts

Script for identifying deadlocked processes

A useful script for identifying SQL deadlock cause/victim.

WITH [Blocking]
AS (SELECT w.[session_id]
   ,s.[original_login_name]
   ,s.[login_name]
   ,w.[wait_duration_ms]
   ,w.[wait_type]
   ,r.[status]
   ,r.[wait_resource]
   ,w.[resource_description]
   ,s.[program_name]
   ,w.[blocking_session_id]
   ,s.[host_name]
   ,r.[command]
   ,r.[percent_complete]
   ,r.[cpu_time]
   ,r.[total_elapsed_time]
   ,r.[reads]
   ,r.[writes]
   ,r.[logical_reads]
   ,r.[row_count]
   ,q.[text]
   ,q.[dbid]
   ,p.[query_plan]
   ,r.[plan_handle]
 FROM [sys].[dm_os_waiting_tasks] w
 INNER JOIN [sys].[dm_exec_sessions] s ON w.[session_id] = s.[session_id]
 INNER JOIN [sys].[dm_exec_requests] r ON s.[session_id] = r.[session_id]
 CROSS APPLY [sys].[dm_exec_sql_text](r.[plan_handle]) q
 CROSS APPLY [sys].[dm_exec_query_plan](r.[plan_handle]) p
 WHERE w.[session_id] > 50
  AND w.[wait_type] NOT IN ('DBMIRROR_DBM_EVENT'
      ,'ASYNC_NETWORK_IO'))
SELECT b.[session_id] AS [WaitingSessionID]
      ,b.[blocking_session_id] AS [BlockingSessionID]
      ,b.[login_name] AS [WaitingUserSessionLogin]
      ,s1.[login_name] AS [BlockingUserSessionLogin]
      ,b.[original_login_name] AS [WaitingUserConnectionLogin] 
      ,s1.[original_login_name] AS [BlockingSessionConnectionLogin]
      ,b.[wait_duration_ms] AS [WaitDuration]
      ,b.[wait_type] AS [WaitType]
      ,t.[request_mode] AS [WaitRequestMode]
      ,UPPER(b.[status]) AS [WaitingProcessStatus]
      ,UPPER(s1.[status]) AS [BlockingSessionStatus]
      ,b.[wait_resource] AS [WaitResource]
      ,t.[resource_type] AS [WaitResourceType]
      ,t.[resource_database_id] AS [WaitResourceDatabaseID]
      ,DB_NAME(t.[resource_database_id]) AS [WaitResourceDatabaseName]
      ,b.[resource_description] AS [WaitResourceDescription]
      ,b.[program_name] AS [WaitingSessionProgramName]
      ,s1.[program_name] AS [BlockingSessionProgramName]
      ,b.[host_name] AS [WaitingHost]
      ,s1.[host_name] AS [BlockingHost]
      ,b.[command] AS [WaitingCommandType]
      ,b.[text] AS [WaitingCommandText]
      ,b.[row_count] AS [WaitingCommandRowCount]
      ,b.[percent_complete] AS [WaitingCommandPercentComplete]
      ,b.[cpu_time] AS [WaitingCommandCPUTime]
      ,b.[total_elapsed_time] AS [WaitingCommandTotalElapsedTime]
      ,b.[reads] AS [WaitingCommandReads]
      ,b.[writes] AS [WaitingCommandWrites]
      ,b.[logical_reads] AS [WaitingCommandLogicalReads]
      ,b.[query_plan] AS [WaitingCommandQueryPlan]
      ,b.[plan_handle] AS [WaitingCommandPlanHandle]
FROM [Blocking] b
INNER JOIN [sys].[dm_exec_sessions] s1
ON b.[blocking_session_id] = s1.[session_id]
INNER JOIN [sys].[dm_tran_locks] t
ON t.[request_session_id] = b.[session_id]
WHERE t.[request_status] = 'WAIT'
GO

View Post (85) or Add Comments (0)


placeholde.rs - A hosted image placeholder service for developers & designers

placeholde.rs is a hosted image placeholder service for developers & designers. Just specify width and height, tweak the parameters and grab the URL.

View Post (1769) or Add Comments (4)


Engaging Business Customers with Mobile in 2014 - Apps vs. Mobile Websites

When we started the process of delivering a business mobile application to our customers, we asked ourselves a fundamental question which has haunted development teams and project managers for many years now; should we go native or mobile web in our development approach and, more importantly, why do we have to make this decision in the first place?

To answer this question, we first looked at the consumer market for trends. A recent report by Flurry shows that consumers only spend 20% of mobile time on websites. The remainder is spent in mobile applications such as social networking and games.  Businesses however are showing the complete opposite trend. A 2013 Forrester report reports that almost 60% of companies surveyed stated that developing a mobile experience for customers was a high priority, but just 44% reported that they were focusing on a mobile app, with a whopping 56% opting for a mobile-optimised version of their current system.

A link between consumer and businesses trends

We can see from the surge in BYOD and BlackBerry's recent dip in market share that business users want to use familiar tools at work.  We also know that mobile, fixed-line and IT operate differently and learned from our customers that technological expectations of staff in this market sector are higher. Despite implementing responsive design in our application, we found that they wanted their data to be closer and more convenient.  Users have been spoiled by the benefits of 'now' apps which don't require login or navigation and present the data you need instantly.  Digital banking apps are a great example of this; many of the app features like being able to log in and stay logged in for easy access to your account information, having a screen code to keep it secure, and being able to transfer money easily, things that are only possible because we're able to tap into the device's native features.

A paradigm "nudge" - the best of both worlds

Proper design & build of mobile applications requires significant investment in time, money and resources which may lead many a development team to come to the conclusion that a single, responsive website, built on HTML5, may be a viable alternative to a native applications.  There was a time when many developers thought HTML5 would completely eliminate the need for mobile apps, with industry experts telling us that we'll forget the day we ever wrote native apps. However, in an interesting twist of fate, HTML5 is actually being used a tool for cross-platform native app development. In fact, it’s now the number one choice for developers building apps for multiple platforms. Tooling like PhoneGap and Telerik's App Builder are leading the way in turning HTML5 and JavaScript into usable cross-platform apps using Apache Cordova- "a platform for building native mobile applications using HTML, CSS and JavaScript."

Why is mobile engagement increasing and which approach should I take?

For experienced business users, apps are more engaging because they utilise more of the built-in capabilities of your smartphone or tablet.  For now, it’s important to offer both options to users, because mobile apps and mobile sites are different tools for different tasks. But as more and more device options and development platforms become available, it'll  be interesting to see how the consumer vs. business usage stats change.

View Post (2662) or Add Comments (0)


The SSE Hydro Arena, Glasgow - Photo & Video Timeline

24 September 2013

24 September 2013

24 September 2013

24 September 2013

24 September 2013

24 September 2013

14th September 2013

28th August 2013

17th July 2013

9th June 2013

25th May 2013

20th May 2013

23rd February 2013

13th October 2012

13th October 2012

14th September 2012

1st June 2012

6th April 2012

6th April 2012

3rd February 2012

6th November 2011

Interior - 13th August 2013

View Post (8106) or Add Comments (0)


Handling Unauthorised Ajax Requests in ASP.NET MVC App

The following post describes an application-wide method of handling unauthorised Ajax posts within an ASP.NET MVC application.

Modifying the Authorize attribute as per the example below shows how HandleUnauthorizedRequest can be overridden, returning a Ajax401Response when using Ajax. You're then able to intercept all requests using jQuery and process them accordingly.

Custom Authorize Attribute

using System.Web;
using System.Web.Mvc;

namespace MyApplication.Attributes
{
    /// 
    /// Custom authorisation attribute to return 401 request when Ajax request posted and user session has expired
    /// 
    public class AjaxAuthoriseAttribute : AuthorizeAttribute
    {
        private class Ajax401Response : ActionResult
        {
            // Called by the MVC framework to run the action result using the specified controller context
            public override void ExecuteResult(ControllerContext context)
            {
                context.HttpContext.Response.StatusCode = 401; // The request requires user authentication
                context.HttpContext.Response.Write("Please log out and back in again to continue"); // HTTP response
                context.HttpContext.Response.End();
            }
        }

        /// 
        /// Overriding AuthorizeCore as an entry point for custom auth from base controller
        /// 
        /// The HTTP context, which encapsulates all HTTP-specific information about an individual HTTP request.
        /// 
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (!_authorisable) // When _authorise is false, don't perform authorisation
                return true;

            var result = base.AuthorizeCore(httpContext);

            return result;
        }

        /// 
        /// Encapsulates the information for using AuthorizeAttribute. The filterContext object contains the controller, HTTP context, request context, action result, and route data.
        /// 
        /// 
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
            {
                filterContext.Result = new Ajax401Response(); // return 401 - unauthorised
            }
            else
                base.HandleUnauthorizedRequest(filterContext);
        }


        private readonly bool _authorisable;

        public AjaxAuthoriseAttribute()
        {
            _authorisable = true;
        }

        // AjaxAuthorise can be turned on in any base controller if required
        // Switch it off with this constructor
        public AjaxAuthoriseAttribute(bool authorisable)
        {
            _authorisable = authorisable;
        }
    }
}

You can then handle the response on the client side using jQuery

<script type="text/javascript">
var errorMessageThrottlerEnabled = false;
$(document).ready(
    function() {
        $("body").ajaxError(
            function(e, request) {
                if (request.status == 401) {
                    if (errorMessageThrottlerEnabled)
                        alert(request.responseText);
                    window.location = '/SSO/LogOff';
                    errorMessageThrottlerEnabled = true;
                }
            }
        );
    }
);
</script>

View Post (2627) or Add Comments (0)


You can manage your Kewney.com account by logging in. [ Log On ]