Chinh Do

MSMQ Installation on Windows Server 2008 Fail with 0x80070643

First time here? Check out my greatest hits or look around in the archives, and consider subscribing to the latest posts via RSS or email. I am also on Twitter and Google Plus. Thanks for visiting.
10th May 2010

MSMQ Installation on Windows Server 2008 Fail with 0x80070643

If you get one of these errors starting MSMQ Server or installing MSMQ on Windows (Server 2008), this article describes a potential solution:

  • You cannot start MSMQ Service with the following entry in the Application Event Log: The Message Queuing service cannot start. The internal private queue ‘admin_queue$’ cannot be initialized. If the problem persists, reinstall Message Queuing. Error 0xc00e0001.
  • You cannot install MSMQ with the following error: Attempt to install Message Queuing Server failed with error code 0x80070643. Fatal error during installation. The following features were not installed: Message Queuing Services/Message Queuing Server.

    MSMQ Installation Result

 

For me, the solution was to delete the Registry key KEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSMQ, then try the installation again.

See also:

posted in Dotnet/.NET - C#, MSMQ, Programming | 8 Comments

27th March 2010

Don’t hire ghost hunters who are afraid of ghosts

Your house is haunted. You can’t stand living with the ghosts anymore and decide to call in the professional, a ghost hunter. The ghost hunter comes, nicely equipped with all kinds of shiny ghost hunting equipment, and proceeds to immediately pass out and fall to to the floor with a loud thud at first sight of the ghosts.

Well, in a nutshell, that is the story of the new Event Viewer in Windows Vista and Windows Server 2008. The new Event Viewer looks very nice and all. Trouble is, it now won’t work when there is a syntax error in machine.config or other .NET Framework problems. Apparently, in Windows Vista and Windows 2008, someone at Microsoft decided to rewrite the Event Viewer utility (a perfectly usable and solid utility in previous versions of Windows) in .NET.

MMC could not create the snap-in. The snap-in might not have been installed correctly. Name: Event Viewer.

So, the lesson I learned from this is: don’t hire ghost hunters who are afraid of ghosts. Or, don’t write a utility designed to view monitoring and troubleshooting messages that can fail due to unnecessary dependencies. A critical system troubleshooting utility such as Event Viewer should be the last thing that fails.

What to do when you cannot run Event Viewer in Windows Vista/Windows Server 2008/or Windows 7?

If you get the following error:

MMC could not create the snap-in. The snap-in might now have been installed correctly. Name: Event Viewer. CLSID: FX:{b05566ad-fe9c-4363-be05-7a4cbb7cb510}

Try the following:

  • Fix any syntax errors in machine.config. Restore to a previously known working copy.
  • Rename EventVwr.exe.config in %WINDIR%\System32.

posted in Dotnet/.NET - C#, Programming | 1 Comment

20th February 2010

SQL Server Implicit String Conversion/Concatenation (XML parsing: line <x>, character <y>, unexpected end of input)

If you are getting this error in your SQL Server T-SQL script:, you may be running into an issue with implicit string conversion in SQL Server:

declare @xml varchar(max), @doc XML, @stringVariable varchar(256)
set @stringVariable = 'a string value'

-- @doc is set by concatenating multiple string literals
-- and string variables, with all the variables having less than
-- or equal to 8000 characters
set @xml = '<root>' +
... + @stringVariable +
...
'</root>'

print len(@xml)

set @doc = @xml

Output

8000
Msg 9400, Level 16, State 1, Line 4
XML parsing: line 64, character 74, unexpected end of input

As you can see in the output, the @xml variable was truncated to 8000 characters, resulting in an invalid XML. This is due to the way SQL Server performs implicit string conversions when concatenating strings. When all the string literals/variables involved in the concatenation are 8000 characters or less, the resulting string will be exactly 8000 characters.

The same issue occurs with NVARCHAR data type. Instead of the 8000-character limit, it’s 4000 characters.

A simple fix is to make sure at least one of the string variables is of type VARCHAR(MAX):

declare @xml varchar(max), @doc XML, @stringVariable varchar(256)
declare @x varchar(max)

set @stringVariable = 'a string value'
set @x = ''

set @xml = @x + '<root>' +
... + @stringVariable +
...
'</root>'

print len(@xml)

set @doc = @xml

 

More Info

posted in Database, Programming | 5 Comments

6th February 2010

Using a Different Configured Binding in WCF Client

To programmatically switch bindings on the fly, you can do it via the constructor of the generated client:

var client = new WeatherClient(“MyEndpoint”);

“MyEndpoint” is the name of the endpoint defined in your config file:

<client>
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="http1" contract="MyContract" name="MyEndpoint" />
</client>

posted in Dotnet/.NET - C#, Programming | 0 Comments

23rd January 2010

WCF Client Error “The connection was closed unexpectedly” Calling Java/WebSphere 7 Web Service

If you get the following exception calling a WebSphere web service from your .NET WCF Client (service reference):

System.ServiceModel.CommunicationException: The underlying connection was closed: The connection was closed unexpectedly. —>  System.Net.WebException: The underlying connection was closed: The connection was closed unexpectedly.

Try adding this code before the service call:

System.Net.ServicePointManager.Expect100Continue = false;

More info on the 100-Continue behavior from MSDN.

posted in Dotnet/.NET - C#, Java, Programming | 2 Comments

16th January 2010

Give The Power of Speech and Sound to Your PowerShell Scripts

Do you ever have the problem where you start a long running script (such as running a code build), multi-task on something else on another monitor while waiting for the script to finish, and then totally forget about the script until half an hour later? Well, here’s a solution your problem: have your script give you holler at you when it’s done.

Hello sir! I am done running your command!

In my library script file, I have the following functions to play sound files and to speak any text:

function PlayMp3($path) {
    # Use the default player to play. Hide the window.
    $si = new-object System.Diagnostics.ProcessStartInfo
    $si.fileName = $path
    $si.windowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden
    $process = New-Object System.Diagnostics.Process
    $process.startInfo=$si
    $process.start() 
}

function PlayWav($path) {
    $sound = new-Object System.Media.SoundPlayer;
    $sound.SoundLocation="$path";
    $sound.Play();
}

function Say($msg) {
    $Voice = new-object -com SAPI.SpVoice
    $Voice.Speak($msg, 1 )
}

If you like the text-to-speech feature but find Windows’ speech engine lacking, check out Ivona. It’s a commercial text-to-speech engine but you are allow to generate and download short speech files for free personal use. Now, my script can nicely interrupt me to tell me when it’s done. Other online text-to-speech engines: vozMe, SpokenText.

If Making Noise Is Not Your Thing

If making noise is not your thing, consider displaying a message in the Notification Area. Here’s the code (courtesy Microsoft TechNet):

Build complete!

function Get-ScriptName {
    $MyInvocation.ScriptName
} 

function DisplayNotificationInfo($msg, $title, $type) {
    # $type - "info" or "error"
    if ($type -eq $null) {$type = "info"}
    if ($title -eq $null) {$title = Get-ScriptName}

    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    $objNotifyIcon = New-Object System.Windows.Forms.NotifyIcon 
    # Specify your own icon below
    $objNotifyIcon.Icon = "C:CdoScriptsFolder.ico"
    $objNotifyIcon.BalloonTipIcon = "Info"  
    $objNotifyIcon.BalloonTipTitle = $title
    $objNotifyIcon.BalloonTipText = $msg

    $objNotifyIcon.Visible = $True 
    $objNotifyIcon.ShowBalloonTip(10000)
}

posted in PowerShell, Programming | 2 Comments

7th January 2010

Automating Maven with PowerShell

I found out the hard way that mvn (Maven) on Windows always return a success code of true, which means you cannot use the return code ($?) to check whether the mvn command succeeded or failed. Why they decided to break this seemingly basic program contract is a mystery. A work-around is to scan the mvn output and look for specific strings such as “BUILD SUCCESSFUL”.

Here’s how:

function InvokeAndCheckStdOut($cmd, $successString, $failString) {
    Write-Host "====> InvokeAndCheckStdOut"
    $fullCmd = "$cmd|Tee-Object -variable result" 

    Invoke-Expression $fullCmd
    $found = $false
    $success = $false
    foreach ($line in $result) {
      if ($line -match $failString) {
       $found = $true
       $success = $false
       break
      }
      else {
       if ($line -match $successString) {
        $found = $true
        $success = $true
        #"[InvokeAndCheckStdOut] FOUND MATCH: $line"
        break
       }
       else {
        #"[InvokeAndCheckStdOut] $line"
       }
      }
    }

    if (! $success) {
      PlayWav "${env:windir}\Media\ding.wav"
      throw "Mvn command failed."
    }

    Write-Host "InvokeAndCheckStdOut <===="
}

function InvokeMvn($cmd) {
    InvokeAndCheckStdOut $cmd "BUILD SUCCESSFUL" "BUILD FAILED"
}

InvokeMvn "mvn clean install"

See Also

posted in PowerShell, Programming | 0 Comments

5th January 2010

Tee-Object and Invoke-Expression in PowerShell

The PowerShell Tee-Object Cmdlet allows you to send command output to a file or a variable, and display it in the console at the same time. This is very useful for those instances where you need to parse the text output of a command. I had a hard time getting it to work with Invoke-Expression. After trying different things, I finally found the solution. To get Tee-Object to work with Invoke-Expression in PowerShell 1, include the Tee command in the Invoke-Expression command like this:

Invoke-Expression "mvn clean install | Tee –variable result”

The following, which I guess is what most people try first, doesn’t work (at least in PowerShell V1). I guess because you are storing the result of the “Invoke-Expression” command itself into the variable instead of “mvn clean install”.

    Invoke-Expression "mvn clean install” | Tee -variable result

Wrapping Invoke-Expression in parenthesis (see below) works, but has a drawback: the output is not written to Standard Out until the whole command finishes.

    (Invoke-Expression "mvn clean install”) | Tee -variable result

posted in PowerShell, Programming | 1 Comment

10th December 2009

Create a Temporary File in PowerShell

$tempFile = [IO.Path]::GetTempFileName()

An empty file created immediately when you call this method. Remember to clean it up when are you done!

image

posted in PowerShell, Programming | 0 Comments

2nd April 2009

Convert List<T>/IEnumerable to DataTable/DataView

Here’s a method to convert a generic List<T> to a DataTable. This can be used with ObjectDataSource so you get automatic sorting, etc.

/// <summary>
/// Convert a List{T} to a DataTable.
/// </summary>
private DataTable ToDataTable<T>(List<T> items)
{
    var tb = new DataTable(typeof (T).Name);

    PropertyInfo[] props = typeof (T).GetProperties(BindingFlags.Public | BindingFlags.Instance);

    foreach (PropertyInfo prop in props)
    {
        Type t = GetCoreType(prop.PropertyType);
        tb.Columns.Add(prop.Name, t);
    }


    foreach (T item in items)
    {
        var values = new object[props.Length];

        for (int i = 0; i < props.Length; i++)
        {
            values[i] = props[i].GetValue(item, null);
        }

        tb.Rows.Add(values);
    }22/

    return tb;
}

/// <summary>
/// Determine of specified type is nullable
/// </summary>
public static bool IsNullable(Type t)
{
    return !t.IsValueType || (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Nullable<>));
}

/// <summary>
/// Return underlying type if type is Nullable otherwise return the type
/// </summary>
public static Type GetCoreType(Type t)
{
    if (t != null && IsNullable(t))
    {
        if (!t.IsValueType)
        {
            return t;
        }
        else
        {
            return Nullable.GetUnderlyingType(t);
        }
    }
    else
    {
        return t;
    }
}
  • 1/22/2010 – Fix to support Nullable types.

posted in Dotnet/.NET - C#, Programming | 23 Comments