Friday, April 15, 2011

Career Transitions Presentation to Ball State University

I was asked to speak to the Six Sigma Student Organization in the Whitinger Business Building about the transitions a person may fear while changing roles of a student to professional as well as transitions that may take place while a person is pursuing their career. The talking points from my presentation are below.

Wednesday, April 13, 2011

SQL Saturday #67 Chicago

SQLSaturday 67 LogoMost of the sessions I attended involved improving performance. Whether it was proactive (design for performance) or reactive (troubleshooting), most sessions included some coverage of indexes. Surprisingly there very little duplication of content by the different speakers. Because of the quality and relevance of the all sessions offered, it was difficult to decide which sessions to attend. Below is a brief recap of the ones I chose.

Sessions

Performance Tuning Made Easy with Thomas LaRock

Being a certified Six Sigma Black Belt, I appreciated the way Tom (blog|twitter) described a simple systematic process for performance tuning based on the Six Sigma DMAIC (Design, Measure, Analyze, Improve, Control) approach.

The Optimizer, Statistics, and Indexes with Grant Fritchey

Grant (blog|twitter) gave a great primer to the internals of the Relational Engine, the components of which have really cool names like Query Parser, Algebrizer, and Optimizer. He also spent more time discussing the Statistics histogram, which appeals to my six sigma senses, than I generally see in an hour long presentation.

WIT (Women in Technology) Panel: Energizing the Next Generation

This session seemed to have a balanced number of men and women in attendance. It was nice to hear the perspective of multiple women with different backgrounds sharing their experiences in the field. I’m really happy that most of their experiences sounded positive even in the face of adversity.

Refactoring SQL with Jeremiah Peschka

Jeremiah (blog|twitter) really highlighted the importance of using consistent naming conventions and common alias names. He touched on SQL unit testing and some open source test frameworks. He also showed refactoring examples such as, re-writing where clauses to move functions from the left side of the operator to the right side for performance gains.

Database Design Contentious Issues with Karen Lopez

This was one of my favorite sessions. It was interactive as the participants had to walk to the front of the room and anonymously vote (via post-it note) on a scale of 1 to 5 on our opinion/view of two issues which people often passionately argue about, such as, surrogate keys vs. natural keys. People that admitted to voting on the extremes (one or five) were asked to explain why they voted the way they did and open the topic for group discussion. Karen liberally made effective use of Canadian SWAG (like ketchup flavored Pringles) to persuade the edge-case voters to plead their case in the face of possible peer criticism. Karen (blog|twitter) expertly moderated the discussion and provided great pro/con examples on both sides even where it conflicted with her own views. It was both fun and educational.

Index Internals for Mere Mortals with Michelle Ufford

At a lightning quick pace, Michelle (blog|twitter) brought a great deal of insight to index internals. She showed actual representations of index pages and pointed out key elements of it, including the “uniqueifier”. She covered a great deal of information in the short one hour, but it was very clear, understandable, and educational.

Lunch

The lunch was provided by Meaty Balls. It was plenty of tasty meat and mushrooms for the price.

Check-in

The organizers offered a “Speed Pass” option where I printed my name tag, lunch ticket, and raffle tickets off in advance which meant I could sleep in a little before heading to Chicago.

Venue

The conference was hosted at the DeVry University Addison Campus which had great classroom spaces. There were ample power outlets available on the table tops for each attendee to plug in, if desired. I wish I had remembered to bring the AC adapter for my GPS for the trip home since my car lighter adapter stopped working before the trip.

Networking

I was within a SWAG keychain throw of several SQL Celebrities like Kevin Kline (blog | twitter) and Brent Ozar (blog|twitter). Brent was sitting behind me in three out of five sessions I attended - and no, I’m not a SQL Stalker.

I finally got to meet Wendy Pastrick face-to-face after several email and twitter conversations over the last year.

Credit-worthy

I’ve been running the fwPASS User Group for a few years and to do just an average job takes a surprising amount of time and effort. See my case study on continuous improvement in a professional association for more information. The organizers did an exceptional job that deserves more thanks than I can provide. I’m not sure if this is inclusive of all the organizers (which I copied from Doug Lane’s blog), but THANK YOU:

Wendy Pastrick (blog|twitter)
Ted Kruger (blog|twitter)
Norman Kelm (blog|twitter)
Jes Borland (blog|twitter)
Bob Pusateri (blog|twitter)
Aaron Lowe (blog|twitter)
Bill Lescher (twitter)
Rich Rousseau (twitter)

Thursday, April 7, 2011

IIS is Missing XAP Mime Type for Silverlight Application

lego mimeUpon navigating to the web page hosting a newly deployed Silverlight application, I received the following error:

Error: Unhandled Error in Silverlight Application
Code: 2104   
Category: InitializeError      
Message: Could not download the Silverlight application. Check web server settings  

Thanks, but which server settings? In my case the MIME type for the .xap extension was missing in IIS7. I’m not sure why it was missing since .xaml and .xbap were already defined. I simply added the “.xap” extension and it’s corresponding MIME Type “application/x-silverlight-app” and all was well.
Xap Missing Mime Type In IIS

photo credit: e v a . p é b a r / CC BY 2.0

File URI invalid for WCF HTTP Endpoint

System.ArgumentException: The provided URI scheme 'file' is invalid; expected 'http'.

disconnectedThe error occurred when debugging a Silverlight app that uses Windows Communication Foundation (WCF). When running the debugger, the IDE was launching the html file hosting the Silverlight application, but it was launching it in the browser using a file path, F:\Projects\MyLOBApp\Bin\Debug\TestPage.html, not through IIS as http://localhost/MyLOBApp/TestPage.html. The application was using the following code in a global application class to set the URL to the WCF service.

public static string WebServiceUrlPath
{
    get
    {
        Uri uri = new Uri(Application.Current.Host.Source, "../AppDataService.svc");
        return uri.AbsolutePath.ToString(); 
    }
} 

My solution consists of two projects:


  1. The Silverlight application project
  2. The WCF service project

Upon closer inspection of the file path, Visual Studio was launching the test page from the Silverlight project when it should have been launching the test html page from the WCF project. The simple solution was to set the WCF project as the StartUp Project. That should have been more obvious especially in light of the following message box that popped up before the debugger started, but it was initially overlooked because of the similar project names and html page filenames in the two projects.


image


photo credit: satemkemet / CC BY-SA 2.0

Friday, April 1, 2011

Javascript Deserialization Error Converting Ajax JSON in ASP.Net Web Service

fast light wave runner - like jQuery ajaxThe .Net framework makes it very easy to do fast lightweight AJAX calls to an ASP.Net web service using jQuery or other frameworks using json (JavaScript Object Notation) and XMLHTTPRequest (MUCH faster and lighter weight than the UpdatePanel).

Because the data in json is delimited by apostrophe’s, having them within the text (as the data itself) can throw a deserializing error when ASP.Net parses the json text body into the web service method parameters. A simple way to prevent is to wrap your javascript variable with the escape() method. It will convert an apostrophe to %u2019. On the server side within your web method before you pass the data to the database, you can wrap it with Server.UrlDecode() to convert it back to an apostrophe.

Javascript jQuery Ajax call

Below is an example of a typical jQuery asynchronous call to a web service. Note the webservice name is AppWebService.asmx. UpdateComments is the web method being called. The UpdateComments web method takes two parameters an integer RecordID and a string RecordComments. Note the use of escape(RecordComments) to encode the RecordComments field in the event that it contains apostrophes (or other special characters).

var options = {
    type: "POST",
    url: "/Application/AppWebService.asmx/UpdateComments",
    data: "{'RecordID':" + RecordID + ", 'RecordComments':'"
        + escape(RecordComments) + "'}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (response) {
        if (response.d == "") {
            jQuery('#saving').hide();
        }
    }, //end success
    error: function (response) {
        alert("Sorry, the update failed. \n\n Details follow: " 
    + response.responseText);
    } //end error
};
 
//Call the Web service
jQuery.ajax(options);

 

Raw Request Captured in Fiddler


slow ferry boat - like full page postback or UpdatePanelThe text below is the contents of the HTTP request that is sent to the web service. In this case the actual data is much smaller than the request header information. You can see how much less data is being sent back to the server for processing compared with a complete page postback or even an ASP.Net AJAX UpdatePanel. The json data itself is:


{'RecordID':10629, 'RecordComments':'cat%u2019s%20meow'}


The RecordComments text is an encoded version of “cat’s meow” (without the quotes).


POST http://domain/Application/AppWebService.asmx/UpdateComments HTTP/1.1
x-requested-with: XMLHttpRequest
Accept-Language: en-us
Referer:
http://domain/Application/RecordMaintenance.aspx
Accept: application/json, text/javascript, */*
Content-Type: application/json; charset=utf-8
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0
Host: kestrel
Content-Length: 148
Connection: Keep-Alive
Pragma: no-cache


{'RecordID':10629, 'RecordComments':'cat%u2019s%20meow'}


Web Method accepts json


Behind the scenes ASP.Net parses the json data and uses it to populate the web method parameters. If there was an apostrophe in the json text body as shown below:


{'RecordID':10629, 'RecordComments':'cat's meow'}


ASP.Net would not correctly parse the data correctly, because it would be expecting a closing bracket } immediately after 'cat'. Since we escaped the data, it is parsed correctly using the following web method. Note the use of Server.URLDecode to convert the RecordComment from “cat%u2019s%20meow” back to “cat's meow” before passing it to the helper method as a parameter for a stored procedure.



<WebMethod()> _
<ScriptMethod()> _
Public Function UpdateComments(ByVal RecordID As Integer, ByVal RecordComments As String) As String
 
    Dim result As String = String.Empty
    Try
        CommonSQL.ExecuteNonQuery("sproc_name", _
           RecordID, _
           Server.UrlDecode(RecordComments))
 
    Catch ex As Exception
        Return ex.ToString
    End Try
 
    Return result
End Function

 


photo credit (wave runner): db2r / cc BY-SA 2.0