Go to content Go to navigation Go to search

Brokenwire.NET::programming

SQL Server Service Broker: cleanup
· 2008-06-05 09:26 by Thijs Kroesbergen for Brokenwire.NET

Imagine that you've been playing with the SQL Server Service broker, and you've got thousands of conversations stuck in the queue. And then you discover that there is nothing like "truncate table" possible on the queue... You can cleanup each conversation in the queue with the "end conversation with cleanup" statement.

So, a bit of searching and this is the result:

WARNING: DO NOT USE THIS ON A PRODUCTION ENVIRONMENT: the messages in the queue are lost forever!

use [YOURDB] declare @handle uniqueidentifier declare conv cursor for select conversation_handle from sys.conversation_endpoints open conv fetch next from conv into @handle while @@FETCH_STATUS = 0 Begin END Conversation @handle with cleanup fetch next from conv into @handle End close conv deallocate conv

To see how many conversations there a left:

select count(*) from sys.transmission_queue

Have fun! (I know I did)
More about the Service Broker and ending conversations soon on this channel.

UPDATE:

The really really quick 'n dirty way:

ALTER DATABASE LogistiekeMeetpuntenAdministratie WITH NEW_BROKER

Permalink -

TFS BuildStore: Stopping and removing builds
· 2008-04-11 12:17 by Thijs Kroesbergen for Brokenwire.NET

Here is a quick tip on how to remove a build that got stuck in your Team Foundation Server build environment.

The scenario: You've started a build and someone else has decided that it's a good idea to shutdown the buildserver... (Hi Martijn!)
After that you're left with a started build in the TFS buildstore with a BuildStatus of "Compilation Started". The problem here is that this build will never finish (because the server was shutdown while building). As an additional bonus you'll have team explorer sorting this build to the top of the list as well, which is confusing. On top of that: the list of builds doesn't have a button to delete a build.

So we want to remove it. How? PowerShell!

I used my friend get-tfs, and added a line to the script for the BuildController object. The complete get-tfs function now looks like this:

function get-tfs ( [string] $serverName = $(Throw 'serverName is required') ) { # load the required dll [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client") $propertiesToAdd = ( ('VCS', 'Microsoft.TeamFoundation.VersionControl.Client', 'Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer'), ('WIT', 'Microsoft.TeamFoundation.WorkItemTracking.Client', 'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore'), ('BS', 'Microsoft.TeamFoundation.Build.Common', 'Microsoft.TeamFoundation.Build.Proxy.BuildStore'), ('BC', 'Microsoft.TeamFoundation.Build.Common', 'Microsoft.TeamFoundation.Build.Proxy.BuildController'), ('CSS', 'Microsoft.TeamFoundation', 'Microsoft.TeamFoundation.Server.ICommonStructureService'), ('GSS', 'Microsoft.TeamFoundation', 'Microsoft.TeamFoundation.Server.IGroupSecurityService') ) # fetch the TFS instance, but add some useful properties to make life easier # Make sure to "promote" it to a psobject now to make later modification easier [psobject] $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName) foreach ($entry in $propertiesToAdd) { $scriptBlock = ' [System.Reflection.Assembly]::LoadWithPartialName("{0}") > $null $this.GetService([{1}]) ' -f $entry[1],$entry[2] $tfs | add-member scriptproperty $entry[0] $ExecutionContext.InvokeCommand.NewScriptBlock($scriptBlock) } return $tfs }

Next I had to figure out the BuildUri for the broken build. I used the following snippet to get all builds with a status of "Compilation Started" from the BuildStore:

$tfs = get-tfs http://tfs-server:8080 $tfs.BS.GetListOfBuilds("TeamProject", "DailyBuild") | where {$_.Buildstatus -eq "Compilation Started"}

Before running this, I made sure no other builds where running and to make sure you are going to delete the correct build you MUST double check the results here! Next I copied the BuildUri from the build that I wanted to stop & delete.

Then the following three lines of PowerShell made the magic happen:

$message = "" $tfs.BC.StopBuild("vstfs:///Build/Build/04102008_134057_94286", [ref] $message) $tfs.BC.DeleteBuild("vstfs:///Build/Build/04102008_134057_94286", [ref] $message)

If something goes wrong the $message variable will be filled with a helpful error message.

By combining the BuildStore and the BuildController objects it is also possible to write an automated build-cleanup mechanism using PowerShell. (TFS2008 has this functionality built-in, but version 2005 doesn't)
The pseudo code for this script would look like this:

Loop through ListOfBuilds WHERE BuildQuality equals "Rejected" (maybe another Quality?)
And for each build found:

Writing this in PowerShell should be easy now. And as usual: the actual implementation of this script is left as an exercise for my dear readers ;)

Let me know if you succeed (or fail, in that case we'll sort it out together).

Permalink -

Calculate your age
· 2008-04-03 11:52 by Thijs Kroesbergen for Brokenwire.NET

Find out how old you are, in days... using PowerShell!

Ready? Here it comes:

([Datetime]::now - (new-object datetime(1981,09,26))).TotalDays

I'm currently 9686 days old. For a more dramatic effect you can replace the .TotalDays with .TotalHours (or minutes, seconds, milliseconds depending on the level of the effect you want to achieve).

Enjoy!

Permalink -

Get the OS version in C#
· 2008-04-02 11:42 by Thijs Kroesbergen for Brokenwire.NET

After I wrote about the new wave of operating systems written in C# I noticed an increase in traffic from people who are looking for something completely different.

They did type C#, Operating system and Version into their favorite search engine, and they found this site. But they didn't find an answer to their question.

So for all these people I now show you how to determine the OS version using C# (and the .NET framework).

The very short answer:

System.OperatingSystem osInfo
=
System.Environment.OSVersion;

By looking at osInfo.Version property and the table with version numbers on the Windows Wikipedia page you can determine the OS version.

Or with PowerShell (just because it's possible)

[System.Environment]::OsVersion

Now on to the more sophisticated version. If you want not only the major versions but also the details about the product types and even information about the edition (suite) the machine is running, then you can use some (more complicated) API's, like GetVersionEx.

First of all you need to understand how the OS version number scheme of Windows works. There is a great article about this subject written by Marius Bancila. In this article he explains how the version scheme is laid out. He also shows how to use C++ and the Platform SDK to get to the information we need.

But you wanted to use C# (or .NET in general), so I've also dug up an article on CodeProject which shows the C# code to get the operating system version. The article on CodeProject is not up-to-date (think Vista, server 2008) but by combining the two articles you can create the complete OS detection code. I leave this as an exercise for those of you who really need this...

Have fun!

Permalink -

Can you spot the difference?
· 2008-03-28 21:29 by Thijs Kroesbergen for Brokenwire.NET

It’s Thijs’ tool time again!

This time I want to introduce you to Beyond Compare, a tool I recently discovered because it was in the toolbox for the project I’m currently working on. Before I used the tool that is shipping with Visual Studio and the platform SDK, Windiff, which is pretty terrible.

So Beyond Compare is just like your average compare tool, but MUCH better.
Why is it better?

The creators of this tool describe it as:

Beyond Compare®, the advanced file and folder comparison utility for Windows, helps you visualize changes in your code, keeps your directories in sync, and validates copies of your data.

If you don’t believe me, or them, (and perhaps you shouldn’t) then you can get a free trial from their site. Additionally you can read a review of Beyond Compare on DonationCoder.com (which has some really nice other tools too, such as the ScreenShotCaptor) or read another praising on CodingHorror.com.

Leave me a comment if you know a better compare tool (Better may be free, or better may be with better functionality). Also, let me know if have other nice tools in your toolbox that I should be aware of.

Permalink -

Singularity: open source C# Operating System
· 2008-03-07 11:16 by Thijs Kroesbergen for Brokenwire.NET

The source code for the Microsoft Research project "Singularity" has been published on CodePlex. I’ve written about Cosmos about a month ago and I’ve had many visitors looking for information about a C# operating systems.

I’ve not yet tried to actually run Singularity from the provided sources, but from the "About" page and the supplied documentation it seems that they have a pretty complete implementation.

From the include slide shows you can conclude that Singularity is actually written in SpeC#, a superset of C# (formerly A#). Their runtime is named "Bartok" and translates the MSIL code to x86 binary code.

The mentioned target scenario is "eHome digital-convergence" which means that Singularity could run on devices like Smart Remotes, Set-Top boxes and Media Servers and provide a common platform for these kind of devices.

If the network support is complete enough, Singularity could also be a nice start for embedded (home automation?) projects.

Furthermore they have include a slide deck which says something about the performance of Singularity in comparison with other OS’s (FreeBSD, Linux, Windows). From these slides you can conclude that the performance currently is very similar to these OS’s!

So far I know about three OS implementations in C#:

  1. Cosmos
  2. SharpOS
  3. Singularity

Concluding from my shallow investigations it seems like Singularity is by far the most complete project, with it’s network support and many demo applications. I’m amazed by the size of this project!

One final highlight for pong-addicts: "Pong.cs" is included!

Ps. for the non-native English speakers (just like me): I looked up "Technological singularity" and that actually means something like an intelligence explosion, caused by the self-improving intelligence of machines, which will eventually surpass human intelligence. Think about that for second, does this project prelude the end of mankind?

Permalink -

Previous Next