One of the first issues I had when getting used to SSMS 2008 for the first time was not knowing how I could kill processes through the UI. One of my coworkers was kind enough to provide me the TSQL below to perform the task I had grown accustom to performing with a UI.

DECLARE @p_SPID int, @p_SQL nvarchar(2000),@dbName nvarchar(100)

   FROM master.dbo.sysprocesses AS p
      JOIN master.dbo.sysdatabases AS d ON( d.dbid = p.dbid )
   WHERE d.Name = @dbName AND p.SPID > 50 -- (because spids of 50 or less are reserved for internal use.)
OPEN #cur_Processes
   SET @p_SQL = 'KILL ' + CONVERT( nvarchar(30), @p_SPID )
   EXECUTE( @p_SQL )
   FETCH NEXT FROM #cur_Processes INTO @p_SPID
CLOSE #cur_Processes
DEALLOCATE #cur_Processes

I was looking for a way to access querystring values with javascript.  I stumbled across a couple of articles that pointed me in the right driection, but unfortunately I forgot to book mark them.  I will try to find them again and provide a link to provide them the proper credit.  In the meantime here is the implementation:

var urlParams = {};
   (function () {
      var e,
      a = /\+/g, // Regex for replacing addition symbol with a space
      r = /([^&=]+)=?([^&]*)/g,
      d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
      q =;
      while (e = r.exec(q))
         urlParams[d(e[1])] = d(e[2]);

// You can reference the querystring value like so...
var variablename = urlParams["QUERYSTRINGNAME"];

I needed to display TIF images that were stored in the database.  Unfortunately it is not as simple as just setting the MIME Type and writing out the binary. So I asked Google and the overwhelming response I saw was to convert the TIF into another image type and then write out the binary.  Here is my take on the solution:

Written in C# (the image is sent via a Generic Handler hence the “context.Response”):

using (MemoryStream stream = new MemoryStream(Content))
   System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
   img.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
   context.Response.ContentType = "image/gif";

I needed to modify a VB.NET 2.0 windows forms application to import data from an 2+GB XML file that is provided by a 3rd party.  The XML file contains multiple high level nodes, however I’m only concerned with nodes that match my “PARENTNODENAME”.  This file contains tens of thousands of “PARENTNODENAME” nodes that I need to parse and the perform various database actions with that data.

The VB.NET Code:

Dim bFirstRead As Boolean = True
Using r As XmlReader = XmlReader.Create(XMLFILENAME)
   While r.Read()
      If (bFirstRead) Then ' Only ReadToDescendant to get down to the "PARENTNODENAME" nodes initially
         bFirstRead = False
      End If

      If r.Name = "PARENTNODENAME" Then
         ' Parse nodes and import into database
      End If
   End While
End Using

I was playing with the HTML5 Canvas element trying to allow client side zooming/panning/rotating of an image.  I finally figured out an implementation that will accommodate the zooming and I am still working on the panning/rotating pieces of the functionality.  I use a SELECT element to act as the scale (Zoom) for the image.  Even though it is not present in the code snippet below, I use a Generic Handler to populate my ASP.NET Image control.  The HTML5 canvas uses the ASP.NET Image control as the source of the image and then I can use JavaScript and the Canvas element to manipulate the image on the client side.


<select id="ZoomSelect" onchange="drawpicture();">
   <option id="Zoom50" value=".5">50%</option>
   <option id="Zoom75" value=".75">75%</option>
   <option id="Zoom100" value="1" selected="selected">100%</option>
   <option id="Zoom125" value="1.25">125%</option>
   <option id="Zoom150" value="1.5">150%</option>
   <option id="Zoom175" value="1.75">175%</option>
   <option id="Zoom200" value="2">200%</option>
<canvas id="viewer"></canvas>
<asp:Image ID="imgViewer" runat="server" style="display:none;" />

The JavaScript:

window.onload = function () {

function drawpicture() {
   var canvas = document.getElementById("viewer");
   var context = canvas.getContext("2d");
   var imageObj = document.getElementById('<%= imgViewer.ClientID %>');
   var scale = $('#ZoomSelect option:selected').val();
   context.clearRect(0, 0, 3000, 3000); // clear canvas for re-draw
   context.canvas.width = imageObj.width * scale;
   context.canvas.height = imageObj.height * scale;
   context.drawImage(imageObj, 0, 0, imageObj.width, imageObj.height, 0, 0, imageObj.width * scale, imageObj.height * scale);

I was working on a few pages where I wanted the content to automatically fill the height/width regardless of browser size.  I set my DIV tag with a id of “Content” and then created the following JQuery automatically scale the DIV tag to the appropriate height and width. I only have one DIV tag that required dynamic height and width so I was able to just subtract the height and width of the other elements on the page.  Replace N with the height/width of the other elements on the page.

The JQuery:

$(function () {
   $('#content').css({ 'height': (($(window).height()) - N) + 'px' });
   $('#content').css({ 'width': (($(window).width()) - N) + 'px' });
   $(window).resize(function () {
      $('#content').css({ 'height': (($(window).height()) - N) + 'px' });
      $('#content').css({ 'width': (($(window).width()) - N) + 'px' });

JQuery Break down:


I use $(window).height() to get the height of the browser window

(($(window).height()) - N)

then subtract the height of the other static elements in my page

$('#content').css({ 'height': (($(window).height()) - N) + 'px' });

Lastly we assign it to the height style property of my DIV tag with the id of Content.

The width functionality is similar except we use $(window).width() instead.

You’ll notice we also cover on window resize by including:

$(window).resize(function () {
      $('#content').css({ 'height': (($(window).height()) - N) + 'px' });
      $('#content').css({ 'width': (($(window).width()) - N) + 'px' });

I was in a situation where I was expanding the functionality of an existing ASP.NET Gridview and I needed to add on-click highlighting and double-click redirecting.  I was browsing the JQuery website for a general idea on what to implement when I eventually pieced this together:

The JQuery:

var selected = null;

$(document).ready(function () {
   $("#<%=GRIDVIEWNAME.ClientID %>").find("tr").hover(function () {
      $(this).css('cursor', 'pointer');
   }, function () {
      $(this).css('cursor', 'default');
   $("#<%=GRIDVIEWNAME.ClientID %>").find("tr").click(function () {
      $(selected).removeClass("selectedrowstyle"); // Removes the CSS class from the previously selected row
      $(this).addClass("selectedrowstyle");        // Assigns the CSS class to the newly selected row
      selected = this;                             // Set the global javascript variable to the newly selected row
   $("#<%=GRIDVIEWNAME.ClientID %>").find("tr").dblclick(function (e) {
      var id = $(this).closest("tr").find("input[type=hidden][id*=HIDDENFIELDNAME]").val();
      window.location = "PAGENAME.aspx?id=" + id;

In the click function I use JQuery to set a class that will change the row background and text color to help the user identify which row was selected.

In the dblclick function I use JQuery to look up an id that is stored in a template column in the gridview.  That template column contains a hidden control that stores a value that I want to pass as a query string to the new page.

The hover function is just there to give me the nice pointer cursor look when a user is hovering over a row.