Archive for 'Tips & Tricks'

T-SQL Remove Space From Records

I noticed that there was a large subset of data in one of my databases that contained a space at the end of every row, this was screwing up my reporting and the space needed to be removed.

Here’s how:

1
2
UPDATE tableName SET columnName = RTRIM(columnName)
WHERE someOtherColumn = 'criteria'

.NET – ToString() vs Convert.ToString()

Calling ToString() on an object almost seems like second nature, however it can cause errors if the object is null.

Calling ToString() on a null object causes the following error

Object reference not set to an instance of an object

The easiest method around this is to use the Convert.ToString() method instead. This casts the object first before trying to convert to a string.

1
2
3
var something = null;
something.ToString(); // Error
Convert.ToString(something); // Success

Debugging A .NET Service With “Attach To Process” In Visual Studio

The tricky thing about building a Windows service is the debugging.   You cant just hit F5 and debug the app from there,  you need to “Attach” to the process.

Thankfully its not very difficult, although some of the guides out there aren’t very clear on this , so follow the following steps and you’ll be debugging in no time.

Continue reading “Debugging A .NET Service With “Attach To Process” In Visual Studio” »

Taskkill – Kill All Process’s Of A Certain Name

So you may have run something thats spawned a whole bunch of processes,  iexplore.exe  or cscript.exe ,  you need to kill them all and fast.   Heres how

1
taskkill /F /IM iexplore.exe

Useful Windows Run Commands

A whole bunch of very useful Windows commands Continue reading “Useful Windows Run Commands” »

Task Scheduler – The following error was reported: 2147944309.

This common task scheduler message is cryptic, and means nothing without some digging,  you can see below how we find the true answer to what it means,  but the short answer is:


Account Is Locked Out

Why?
0n2147944309 = 0x80070775
Facility: 8007 = Win32 (it’s a “Win32″ status code)
Status: 0x775 = 0n1909
Q:\>net helpmsg 1909
The referenced account is currently locked out and may not be logged on to.

T-SQL Setting Date Format

Occasionally you need to run a DATEDIFF or DATEADD against some dates that are in a reverse format, ie Day:Month:Year instead of Month:Day:Year, theres a simple way to set this in your query without having to string handle it all, using the SET DATEFORMAT parameter.

1
2
SET DATEFORMAT dmy
SELECT DATEDIFF(MINUTE,'29-01-2010 09:13:18','29-01-2010 09:18:18')

Windows Task Scheduler – Corrupt Image Error Fix

For some reason now with Vista and Windows Server 2008 when ever you seem to create a scheduled task, but close it before saving it, you get a “Corrupt Image” error that will not go away unless you remove the “Corrupt Image” from the registry.

Heres how to fix it

  1. Open The Registry (Start > Run > regedit)
  2. Browse to HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache
  3. Under the “Tree” folder, find the scheduled tasks that you are having the error with and delete their folder.

Thats it, now re-open task scheduler and the error should be gone.

Pinger! – The Mass Host Ping Tool

PLEASE NOTE:
Pinger! Has Found A New Home At TheMonitoringGuy.com,
Please Visit  http://themonitoringguy.com/software/pinger-mass-host-ping-tool/ To Download The Latest Version Of Pinger!

Pinger! is a tiny ping utility (13KB) that is used to quickly ping a large list of hosts and save the resulting successful and failure host lists into a text file.

Why?

When developing scripts and applications that will touch a large number of hosts,  if many of those hosts are offline or no longer exist, the timeouts involved with this can slow down execution time and dramatically slow down your script or application.

In my case, I was presented with a list of 600+ servers that needed to have the exact same script run against them, a successful server took only several milliseconds to finish,  a failed host took around 4 seconds to time out, clearly I needed to find out which servers were alive and which weren’t and further again I needed to list the successful servers in a clean text file, 1 host per line, so I could import this into my application as an array.

And hence Pinger! was born :)

Usage

Very simple, Pinger.exe when run looks for hosts.txt in the same directory. Simply enter in your list of host names in this text file,  one per line and Pinger! will run over them 1 by 1 and output the results.
Simply extract the .zip containing Pinger.exe and hosts.txt to the same directory and open Pinger.exe.

Output

2 files are outputted.  these are:

  • success.txt – The list of successfully pinged hosts, in per line format
  • failure.txt – The list of hosts that failed to ping, in line by line format.

Download Pinger Here!

IIS7 and Classic ASP – Enabling Error Messages

Recently iv switched a lot of my web apps from an IIS6 to an IIS7 server although this came with a few headaches, one of which was that now, I was unable to debug my code from the browser on my remote machine, instead just seeing an “Error Code 500 – Internal Server Error” message,  which is basically useless.

Iv found the solution, although it involves a few steps,  heres how.

  1. In your IIS7 control panel, under your site home area, double click on the “ASP” icon (In the bottom half, on my window).
    Expand the Debugging Properties toggle , and switch the Send Errors To Browser option to TRUE.
  2. Open up a command line and run this command:
    %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpErrors -errorMode:Detailed
  3. If your using Internet Explorer, go into  Tools > Internet Options > Advanced , find the “Show friendly HTTP error messages” under the “Browsing” section and disable it.
  4. Thats it!  Your done.

FireFox NTLM Authentication – Windows Authentication

Maybe its just me, but having to switch between Internet Explorer and Firefox to access Internal and External sites is a hassle.  Particularly the SharePoint based sites on Firefox.

So iv found a solution ..  If you want to use FireFox for all sites heres what I did to get it working.

In FireFox

Enable auto NTLM authentication for the internal sites that require domain accounts.

  1. Open FireFox and type about:config hit enter
  2. In the filter box type NTLM , find the key -  network.automatic-ntlm-auth.trusted-uris
  3. Add a comma separated string of URLS here .. Example http://intranet,http://somelocalsite,http://sharepoint
  4. Restart firefox

When you visit these sites now, you will be authentication in the same way you are with Internet Explorer without being prompted to login.  This is absorbed from your domain account.

Register ASP.NET Version In IIS

If your IIS Web Service Extensions list is not showing your correct version of ASP.NET, ie It may only show version 1.1.3822 where as your using version 2 in your application, click start > run and then enter this command , replacing the .NET Framework version with your desired version.

1
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_regiis.exe -I

Windows 2008 Perfmon Crashes – Reset User Defined Data Collector Sets

I discovered this very annoying bug in Windows Server 2008 when attempting to import an XML file with 100 serverswind2008 and counters in it.
No doubt one of the server had an issue and therefore and for some stupid reason, perfmon or Reliability And Performance Monitor, as its called now in 2008 is unable to handle this , and completely falls over.
Now, when you open Perfmon and try to view the User Defined Data Collector Sets, or run logman.exe from the command line, the application completely freezes and your unable to delete the corrupt dataset you just imported or even click elsewhere in the window.

In 2003, a reboot would fix this problem, but in 2008 it does not. The solution lies in the registry. Here’s how to fix the problem.

  1. Make sure your logged in as admin or with admin rights
  2. Close any open perfmon (Reliability and Performance Monitor) windows you have open.
  3. Click Start > Run then type  regedit hit enter
  4. Goto: HKLM\Software\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Windows\PLA
  5. You will see your Data Collector Sets in here, delete the one you created that caused the problem (or just delete them all if your not sure) **NOTE** Dont delete the “System” folder.
  6. Your done now, re-open perfmon, or logman and your problem should be solved.

SQL Replace Nulls With Blank String

Simple way to replace NULL values in your queries with blank strings by using the IsNull function.

This will allow for problem free string creation etc.

1
2
3
SELECT IsNull(ColumnName, '') 
As NewColumnName 
FROM TableName

More information can be found here: http://msdn.microsoft.com/en-us/library/ms184325.aspx

Kill All Processes Of Certain Application In Unix/Linux

This is a very helpful command I use regularly.

If your like me, you open several instances of applications like “VI” and leave them in the background, most of the time without meaning to.  Eventually you run a “PS -U” to view all your processes running and realize that theres 10 copies of the application running in the background which you havnt closed. Heres a command to quickly clear that up. Continue reading “Kill All Processes Of Certain Application In Unix/Linux” »

SteerMouse For Mac OSX

Hardest part about moving to a mac was Apples terrible mouse acceleration system and its highly in-accurate  USB rate … It basically made it impossible to do the graphic design work that I used to do on a PC.   Anybody coming from a PC to a mac that does any sort of accurate mouse work will know what im talking about . . . Steermouse fixes that problem and gets your mouse running smooth as silk  .. I highly recommend it ! http://plentycom.jp/en/steermouse/

Embedding XHTML Compliant Flash Files

All to often people all over the web use non-xhtml embedding on their sites.
Use the following code to embed fully XHTML 1.0 compliant flash objects. Continue reading “Embedding XHTML Compliant Flash Files” »

How To Conceal Your Pr0n In a JPG

So your sick of your Girlfriend / Mum / Dad / Brother / Gay mates stumbling across your pr0n right ?  Here’s a little tip that will help solve that problem for good. Continue reading “How To Conceal Your Pr0n In a JPG” »