Tuesday, December 16, 2008

Host [Name] failed while starting monitoring asynchronous operations queue.

I've started working on some Microsoft Dynamics CRM development lately, and came accross this issue with on of our servers when the CRM Asyncronous Service stopped:

Host [Name] failed while starting monitoring asynchronous operations queue.

If you have the ApplicationServer and PlatformServer installed on the same machine, you may receive this error (in the event log) when you try and start the service

Host SGCORPCRM1: failed while starting monitoring asynchronous operations queue. Exception: System.InvalidOperationException: The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly.
at System.Diagnostics.PerformanceCounter.Initialize()
at System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName, String instanceName, Boolean readOnly)
at Microsoft.Crm.Asynchronous.PerformanceCounters..ctor(String instanceName)
at Microsoft.Crm.Asynchronous.AsyncService.OnStart(String[] args)


I'm not sure how this happenned, I had a look for answers and found a Microsft KB on the problem - which was similar, but this did not seem to be applicable.

After some more searching, I finally found a post in the eggheadcafe forums , which came up with the goods (thanks Deepak!). Of course, before applying this fix, I checked a working server first, and found that the RoleNames and Roles registry entries were infact incorrect.

Below I've repeated the steps, hopefully making it easier to find for other with the same issue.
Open the registry and go to the path HKLM\SOFTWARE\Microsoft\MSCRM

  1. Check the 'RoleNames' value and the 'roles' value - they should be set to the following values "ApplicationServer,PlatformServer" and "2392107" ( do not include quotes)
  2. If the values do not match these, correct them to be the same
  3. Repair the CRM Installation
  4. Restart IIS The service should start successfully now.

Friday, December 5, 2008

LINQ to SQL Entity Base Version 1.0 Final

Hi everyone,

Now that all the bugs seem to be ironed out in the the LINQ to SQL Entity Base class, it's time to release it to the world as a final version.

If you have been using RC3, there is no need to update the source code from the Final release source code as it has not changed.

As with the RC3 release, I will stress again that you need Visual Studio 2008 SP1 and .NET 3.5 SP1 to run this final release verison as it uses one of the attributes for serialization not found in the original .NET 3.5 version.

Find the final version here:


Anyway, have fun!

Cheers

Matt.


Wednesday, October 22, 2008

Linq to SQL Entity Base Release Candidate 3

Hi everyone,

I've released a new version of the Linq 2 SQL Entity Base class which can be found here, along with details of the changes:

http://www.codeplex.com/LINQ2SQLEB/Release/ProjectReleases.aspx?ReleaseId=18662

I'm hoping this is the final release candidate that will become version 1.0 gold.

Cheers

Matt.

Friday, October 10, 2008

TFS - Fixing Work Item Updates made in Excel

One of the cool things about TFS is it's integration with Excel. The integration allows you to link work item data and publish it back to TFS, which is really handy for BA's, Team Leaders and Project Managers.

Unfortunately, with this feature comes the ability to make a huge mistake as well if you are not careful.

Recently, I had to find a way to revert 400 hundred work items which were unintentionally updated by one of the business team. They were using excel, copying and pasting from one TFS linked document into another and accidentally answered "yes" to the publish on the target excel document which resulted in every work items title and description being overridden.

Unfortunately, there was not quick and easy way to revert this so I had to figure out some way of doing it.

What I came up with was rather than trying to rollback the changes by fiddling with the TFS database (which is also a very risky thing to do) I thought that I would just override the mistaken records with the previous data (ironically with Excel - which is the same thing that made the mess!) and leave the invalid data in the workitem, so it would dissappear in the history.

Here's what I did:

  1. Queried the "workitemsare" table and the "workitemswere" table to find those records which were accidentally updated (looking at the change date field and the changed by field to find the right time of the incidient and user who publish the records).
  2. Found the previous version of the records by looking in the "workitemswere" table by comparing the records found in 1. above to the "workitemswere" table and finding the most recent update that occurent before the incident.
  3. From the results, build CSV file that could be opened in excel and be pasted over the top of a TFS linked document containing those records which were affected by the incident. It's important that both the excel documents (both the extract and the linked document) were in the same work item order and had the same columns that needed to be updated.
  4. Paste the correct values over the top of the bad records in the linked excel spreadsheet.
  5. Publish the correct values back to TFS from excel, resolving any issues where the new "correct" values broke any TFS workitem status state rules.

If you ever need to do this, here's a sample of the scripts which should get you started:

-----


-- Create a tempory table to put the data in
SELECT 1 AS Id,
fld10010 AS Priority,
State,
[Fld10094] ExternalSystemId,
[Assigned To],
Title,
fld10005 As [Resolved Date],
[Changed Date]
INTO #workingtable
FROM workitemsare
WHERE id = null


-- Grab the data that we are after and throw them into a temp table,
-- filtering by user and approximate time.
INSERT INTO #workingtable
(
id,
Priority,
State,
ExternalSystemId,
[Assigned To],
Title,
[Resolved Date],
[Changed Date]
)
SELECT id,
fld10010 AS Priority,
State,
[Fld10094] ExternalSystemId,
[Assigned To],
Title,
fld10005 As [Resolved Date],
[Changed Date]
FROM workitemsare
WHERE [changed by] = '[user name]'
AND [changed date] BETWEEN '2008-08-26 08:41:00'
AND '2008-08-26 08:42:00'
UNION
SELECT id,
fld10010 AS Priority,
State,
[Fld10094] ExternalSystemId,
[Assigned To],
Title,
fld10005 As [Resolved Date],
[Changed Date]
FROM workitemswere
WHERE [changed by] = '[user name]'
AND [changed date] BETWEEN '2008-08-26 08:41:00'
AND '2008-08-26 08:42:00'

-- select the correct records (finding the most recent change before the incident),
-- making sure that the column order and record order match that of excel spread sheet
-- you will use to paste over the top
-- (export this to CSV)

SELECT WIW.id,
ISNULL(CAST(WIW.fld10010 AS VARCHAR(10)), '') AS Priority,
WIW.State,
ISNULL(WIW.[Fld10094], '') AS ExternalSystemId,
WIW.[Assigned To],
WIW.Title,
WIW.fld10005 As [Resolved Date],
WIW.[Changed Date]
FROM #workingtable MWT
INNER JOIN [WorkItemsWere] WIW ON MWT.Id = WIW.Id
WHERE WIW.[Changed Date] = ( SELECT MAX([Changed Date])
FROM [WorkItemsWere] AS WIW2
WHERE WIW.Id = WIW2.Id
AND WIW2.[Changed Date] < '2008-08-26 08:41:00'
)
GROUP BY WIW.id,
WIW.fld10010,
WIW.State,
WIW.[Fld10094],
WIW.[Assigned To],
WIW.Title,
WIW.fld10005,
WIW.[Changed Date]
ORDER BY WIW.Id

----

Notes:

- Some of the fields have column values that aren't well named (auto genereated by TFS), to find where they are, look in the Fields table for the correct field/column mapping.

- WorkItemsWere, WorkItemsAre, Field tables can be found in the "TfsWorkItemTracking" database.

- WorkItemsWere table contains the previous states of each work item

- WorkItemsAre table contains the latest values for each work item

- DO NOT modify the TFS database directly!!!!


Cheers

Matt

Friday, August 8, 2008

Run Sun Java Application Server 9.1 on Windows Server 2003 as Service

I don't usually dabble in the Java world too much, but had to recently because a client required us to use a Java Solution and we needed to integrate with as part of our Windows Workflow Foundation. This solution Runs under Sun Java Application Server (SJAS).

Installation of the JAR file in SJAS worked fine as a Service and everything seemed to be going great. Right up until I logged off the server - this is where the service stop responding to calls but the service itself still beleived everything was working fine. This was weird because if you choose to install as a service, you don't expect it stop when you logout (i.e.the whole reason for having the "windows service" concept).

There seemed to be a lot of people out there looking for a solution to this issue, but no one seemed to have the answer (at least not for Windows 2003/SJAS 9.1 combination). Not even the vendor of the solution we were integrating with had a solution to this problem.

It turns out that the information is actually in the documentation for SJAS after all - which tripped me up because my searched kept taking me to the old 8.x version SJAS which doesn't include the extra special setting for Windows 2003, and following the 8.x version doesn't work.

Anyway, here's the information and a link to the Sun documenation - it's a bit of fiddling, but it works fine once you make these changes.

http://docs.sun.com/app/docs/doc/819-3671/ablwz?l=en&a=view&q=Restarting+Automatically


Preventing the Service From Shutting Down When a User Logs Out
By default, the Java VM catches signals from Windows that indicate that the operating system is shutting down, or that a user is logging out, and shuts itself down cleanly. This behavior causes the Application Server service to shut down when a user logs out of Windows. To prevent the service from shutting down when a user logs out, set the -Xrs Java VM option.

To set the -Xrs Java VM option, add the following line to the section of the as-install\domains\domain-name\config\domain.xml file that defines Java VM options:

-XrsIf the Application Server service is running, stop and restart the service for your changes to become effective.


And the all imporant bit...


Note –
In some Windows 2003 Server installations, adding the -Xrs option to the domain.xml file fails to prevent the service from shutting down. In this situation, add the option to the as-install\lib\processLauncher.xml file as follows:

<process name="as-service-name">
...
<sysproperty key="-Xrs"/>
...


Thursday, July 3, 2008

Debugging Windows Services in Visual Studio 2002/3/5/8

Just a quick tip on something I've been doing for years.

If you want to debug your Windows Service without having to install it as a service on your development machine first, you can use the "DEBUG" compiler constant to direct the compiler constant to run your service just as an executable instead of spinning up a service.

To do this in C# (basically the same steps in VB as well), open the Program.cs file and wrap the main method contents in a #if(!DEBUG), #else and #endif. Between the #else and #endif, simply put in the code that invokes the application logic.


You can see my example below, I've simply created a class called "ProcessFiles" and added static start and stop methods that starts/stops the processing as it normally would in a service. In the Program.cs file, i've then simply called the start method, put in a message box to stop the process falling through and stopping until developer debugging is read to quit, and a call to the stop method to cease processing.

From there it was just a simple matter of hooking up the OnStart and OnStop events of the actual service class of these methods as well.



namespace ExampleService
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
#if(!DEBUG)


ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service()
};
ServiceBase.Run(ServicesToRun);
#else
ProcessFiles.Start();
MessageBox.Show("Debugging has started. To stop debugging click ok");
ProcessFiles.Stop();

#endif

}
}
}


The "DEBUG" compliler constant is linked to the Build Properties Page on a C# project. By defualt this is ON for the "DEBUG" build configuration, but OFF for releases. You'll notice if you are looking at the code, that when your build configuration is set to "DEBUG:, the generated service code will be greyed out and the custom code comes to life. Switching to "RELEASE" config reverses this situation. Nice touch I think ;)

Now I can use the "RELEASE" config to build an exe so my solution can be deployed as a service for testing/production OR simply run it in the Visual Studio debugger under the "DEBUG" config without having to install it as a service on my dev machine.


Cheers

Matt.

Wednesday, June 25, 2008

Hyper-V - Great for Developers

I've been using Microsofts Hyper-V software for the last month and I gotta say I'm impressed.

At work, we've setup box with 1 Terrabyte of Hard Drive Space (Raid 10), 16GB of RAM and two Quad Core Xeons running Windows Server 2008 x64 and Hypervisor. This is being used for our Test and User Acceptance platform - allow us to create our environments very rapidly (with some help from Sys Prep) and performance is amazing considering we are running 10 VPC's, some even running Biztalk + SQL server instances inside the virtuals as well. I have not yet seen even a hint of any drop in performance and still plenty of room for expansion with this hardware.

The difference between Hyper-V and other Microsoft Virtual technolgies is that the Windows 2008 OS actually allows Hyper-V to sit a hell of a lot closer to the metal (i.e. less layers between the Virtual and the Physical hardware) while still doing a great job of distributing the load of the VPC's accross the machine. It totally rocks compared to Virtual PC Server - it isn't even close to Hyper-V on performance.


It has definately development lives much easier, being able to spin up a new Syspreped OS, drop it on, hook it up to the network and then install whatever we need. The other thing we've been able to do is to port physical machines to virtual (this comes as an easy step by step wizard) - although I have come across some issues and couldn't get some machines to move accross so easily, but this has let us move our current enviroments on seperate physical machines quickly into the virtual fold. I was further impressed in most cases that you can port a machine from physical to virtual while the physical machine your porting is still online.

Just some things to note if you are interested when using the release candidate...

1. It only runs on Windows Server x64 OS, no other OS is supported.

2. It's currently only at a Release Candidate.

3. Although Windows 2008 Server x64 contains the Integration Services components that are required for it be a guest, these are only compatible with Beta 2 of Hyper-V - When using the release candidate you will need to install a patch in the guest OS to allow these drivers to install correctly (See http://support.microsoft.com/kb/949219).

4. When migrating from a previous Virtual PC VHD to Hyper-V, it may not detect the VMBUS and other things correctly, leaving you without some of the comforts of the Integration Services compents. In order to fix this, use Start-->Run MSCONFIG-->Boot Tab-->Advanced Options and Click Detect HAL and reboot.

5. Also when migrating a previous Virtual PC VHD to Hyper-V, if you can't initally get any network access in the Hyper-V admin tool, set the Virtual PC up so it's using a Legacy network driver - this should fix it.

6. If you are stuck wondering why you can't log into the Hyper-V Adminstration tool, you'll need to get the user that original installed Hyper-V on the machine to log into it first and add you as an Administrator before you can use it yourself.

Anyway, check out this for more info

http://www.microsoft.com/windowsserver2008/en/us/virtualization-consolidation.aspx


Cheers

Matt