Free download: Managing SQL Servers and Policy-Based Management

By DimitriC at August 07, 2012 21:15
Filed Under: Books, Documentation, Training, SQL, Security

From the MS Press blog:

 

Get an excerpt from Microsoft SQL Server 2012 Pocket Consultant (ISBN 9780735663763; 592 pages) selected by author William Stanek. Click here for your PDF.

imageHere’s what you’ll learn:

 

Chapter 1: Managing SQL Servers

Microsoft SQL Server Management Studio is the primary tool you use to manage databases and servers. Other tools available to manage local and remote servers include SQL Server PowerShell, SQL Server Configuration Manager, Database Engine Tuning Advisor, and SQL Server Profiler. You use SQL Server Configuration Manager to manage SQL Server services, networking, and client configurations. Database Engine Tuning Advisor is available to help optimize indexes, indexed views, and partitions, and SQL Server Profiler lets you examine events generated by SQL Server, which can provide helpful details for troubleshooting. In this chapter, you will learn how to use SQL Server Management Studio.

■ Using SQL Server Management Studio

■ Managing SQL Server Groups

■ Managing Servers

■ Using Windows PowerShell for SQL Server Management

■ Starting, Stopping, and Configuring SQL Server Agent

■ Starting, Stopping, and Configuring MSDTC

■ Managing SQL Server Startup

■ Managing Server Activity

 

Chapter 2: Implementing Policy-Based Management

Policy-Based Management is an extensible and scalable configuration framework that you can use to manage servers, databases, and other objects in your data environments. As an administrator, you need to be very familiar with how Policy-Based Management technology works, and that’s exactly what this chapter is about. If you haven’t worked with Policy-Based Management technology before, one thing you’ll notice immediately is that the technology is fairly advanced and has many features. To help you manage this complex technology, I’ll start with an overview of Policy-Based Management and then explore its components.

■ Introducing Policy-Based Management

■ Working with Policy-Based Management

■ Configuring Central Management Servers

■ Managing Policies Throughout the Enterprise

Decimal 2 Binary

By DimitriC at February 21, 2012 11:23
Filed Under: Programming, tips & tricks

From time to time I get a fun question. One of them was this: Please provide a list with powers of 2 accompanied by their binary representation, for let’s say up to 50.

 

First version:

 

   1:  int temp=1;
   2:   
   3:  for(int i = 1; i<=50; i++)
   4:  {
   5:      Console.WriteLine(i+": Dec: "+temp+" - Bin: "+Convert.ToString(temp,2));
   6:      temp = temp*2;
   7:  }

 

This gives the following result:

 

image

 

Here we bump into the maximum of information that can be held by an integer. So for going up to 50, it suffices to change the type of the decimal number to long:

 

   1:  long temp=1;
   2:   
   3:  for(int i = 1; i<=50; i++)
   4:  {
   5:      Console.WriteLine(i+": Dec: "+temp+" - Bin: "+Convert.ToString(temp,2));
   6:      temp = temp*2;
   7:  }

image

So, I could answer the question. But the same problem occurs when you come to the limit of the long-data type (which is at 64).

 

Double, float or decimal are not supported by the Convert.ToString(…) implementation where you can define the toBase-parameter.

Read geographical information from the Windows Regional and Language Settings

By DimitriC at December 13, 2011 08:19
Filed Under: Programming, tips & tricks

Recently I got a question of how in .NET it was possible to read from the Windows Regional and Language Settings. Rather than messing around with the Windows registry, the best way to get this information is to use the RegionInfo-object in the System.Globalization namespace.

 

The code:

 

First of all, don’t forget to add the correct using statement:

   1:  using System.Globalization;

After that it’s just declaring the RegionInfo object and reading the settings you’d like (for the example, i’m reading all the settings):

 

   1:  RegionInfo local = RegionInfo.CurrentRegion;
   2:   
   3:  Console.WriteLine("CurrentEnglishName: "+local.CurrencyEnglishName);
   4:  Console.WriteLine("CurrencyNativeName: " + local.CurrencyNativeName);
   5:  Console.WriteLine("CurrencySymbol: " + local.CurrencySymbol);
   6:  Console.WriteLine("DisplayName: " + local.DisplayName);
   7:  Console.WriteLine("EnglishName: " + local.EnglishName);
   8:  Console.WriteLine("GeoId: " + local.GeoId);
   9:  Console.WriteLine("IsMetric: " + local.IsMetric);
  10:  Console.WriteLine("ISOCurrencySymbol: " + local.ISOCurrencySymbol);
  11:  Console.WriteLine("Name: " + local.Name);
  12:  Console.WriteLine("NativeName: " + local.NativeName);
  13:  Console.WriteLine("ThreeLetterISORegionName: " + local.ThreeLetterISORegionName);
  14:  Console.WriteLine("ThreeLetterWindowsRegionName: " + local.ThreeLetterWindowsRegionName);
  15:  Console.WriteLine("TwoLetterISORegionName: " + local.TwoLetterISORegionName);
  16:  Console.WriteLine("ToString: " + local.ToString());

 

image

 

NOTE: Notice that the ToString() method is also implemented for this class. So calling RegionInfo.CurrentRegion.ToString() will give you the TwoLetterISORegionName.

Read from the Windows Registry using C#

By DimitriC at December 08, 2011 09:49
Filed Under: Programming, Windows, tips & tricks

I’ve added an example in the MSDN Samples repository which explains how to read values from the Windows Registry.

 

Description:

 

The example is a simple Console-application that shows you how to select the correct RegistryHive, and afterwards navigate to the correct key and read the value. Keep in mind that reading from the Windows registry always returns an object of type 'object' so you'll need to cast this value to something that makes more sense. This means that you'll be expected to know what you're going to read (integer, binary, string,...). And last but not least, don't forget to add the Microsoft.Win32 using statement!

The available RegistryHives you can read from (and their corresponding names in the Registry Editor (Start => Run => regedit.exe):

  • - ClassesRoot (in RegEdit: HKEY_CLASSES_ROOT)
  • - CurrentConfig (in RegEdit:HKEY_CURRENT_CONFIG)
  • - CurrentUser (in RegEdit:HKEY_CURRENT_USER)
  • - DynData (Windows' own hive with dynamic data. Some configuration information in Windows must be stored in RAM because it requires fast modification and retrieval that cannot wait for the registry to send it to the hard disk. You can find all this data in the HKEY_DYN_DATA registry key. The information in this key is newly created every time Windows starts. Not visible in RegEdit)
  • - LocalMachine (in RegEdit:HKEY_LOCAL_MACHINE)
  • - PerformanceData (Is used to access performance counters but is not visible in Regedit)
  • - Users (in RegEdit:HKEY_USERS)

You can find the example here.

WCF and certificate-based authentication

By DimitriC at October 06, 2011 08:30
Filed Under: Architecture, Programming, Security, tips & tricks, WCF

If you want your WCF service to use certificate-based (X.509) certification to authenticate the users accessing your service, you’ll need to provide the right configuration on both the client and the server side. The keyword here is configuration. When I first started searching for a solution I knew it had to be done in the configuration file, but, as usual, I kind of underestimated the amount of configuring that had to be done.

 

Especially when you’re looking at the generated configuration file provided by Visual Studio, it’s easy to get lost in all the possible security settings. I once attended a course given by Juval Löwy (IDesign) on WCF where he applauded the fact that the WCF-team had made everything configurable and at the same time warned us for the complexity that came with it.

 

The solution: There is a easy-to-follow example where you can learn how certificate-based authentication for WCF can be done at Mitch Denny’s blog - Using Certificate-based Authentication and Protection with Windows Communication Foundation (WCF)

 

He starts out by creating a simple WCF service (with 1 HelloWorld-method) and afterwards adding the authentication configuration.

Visual Studio 2010: Team explorer issue

Recently I’ve been working on a project with a friend of mine. One of the things we were playing with was Team Foundation Server 2010. So we set it up and I connected to it using Visual Studio 2010 Ultimate. Collaborating was not an issue. Sharing documents, using source control,… everything worked fine. Now I wanted to work on some of my ideas. I wanted to start a new project in Visual Studio, but the only option that was available to me was the “Start new team project” issue:

 

image

 

When clicking here, I got the following error (which is ok since my rights on that TFS server have been revoked):

 

image

The weird thing here is that I have a fully working version of Visual Studio 2010 Ultimate installed, but I only get the Team Explorer functionality. You can verify this by checking the installed components of Visual Studio in the “About”-window (Help –> About Microsoft Visual Studio).

 

To get back to the “normal” mode in Visual Studio (meaning: being able to create new projects and working with VS2010 normally) you need to reset your preferences by doing Tools > Import/Export settings > Import. Here you can choose to reset everything or to import a certain configuration. I chose to import a predefined configuration without backing up my current configuration (wasn’t much use to me anyhow):

 

image

 

I selected the Visual C# Development Settings and pressed “Next”. There I chose to reset all settings and clicked the “Finish” button:

 

image

 

Now that my configuration settings have been restored, I have the regular view in my Visual Studio and I can create projects again!

 

image

Add national holidays to Outlook calendar automatically

By DimitriC at May 17, 2011 19:14
Filed Under: Office, Documentation, tips & tricks

 

In Microsoft Outlook you can automatically add your country’s national holidays.

In the “Tools” menu, select “Options”

 

clip_image002

 

In the “Preferences” tab on the Options-screen there is a “Calendar”-section. Click on “Calendar Options”

 

clip_image004

 

In the “Calendar options”-section of the Calendar Options (I swear, I’m not making this up) press the “Add Holidays…”-button.

 

clip_image006

 

Now a list appears with all the countries for which national holidays are known in Outlook. Select the countries of which you want the holiday information imported in Outlook and click “OK”.

Team Foundation Server 2010 Resources

Here are some resources that might be useful when working with (or learning) Team Foundation Server 2010.

 

Team Foundation Installation Guide for Visual Studio 2010

Description:
Team Foundation Installation Guide 2010 includes instruction for installing Team Foundation Server, Team Foundation Server Proxy and Team Foundation Build Services.

Note: After you download the installation guide, you cannot view its contents unless you right-click the .chm file, click Properties, and then click Unblock.

 

Download

 

Administration Guide for Microsoft Visual Studio 2010 Team Foundation Server

Description: Effective administration of Team Foundation Server is important to the success of your team projects. You can use this downloadable version of the administration content available on MSDN for local review of critical administration concepts, procedures, and walkthroughs.

Download

 

Visual Studio 2010 Team Foundation Server Monitoring Management Pack

Description: The Team Foundation Server 2010 Monitoring Management Pack provides both proactive and reactive monitoring of Microsoft Team Foundation Server 2010. It monitors TFS components such as application tier server instances, team project collections, build servers, and proxy servers.

Download

 

Team Foundation Server Integration Tools (March 2011 Release)

Description: The TFS Integration Tools is a project developed by the Team Foundation Server (TFS) product group and the Visual Studio ALM Rangers to integrate Team Foundation Server with third party systems for migration and synchronization of data.  Although the tools can be used for many purposes, planning, thorough testing and honest evaluation of extra resources and cost that will be required should precede any decision to use the Integration Tools.  The Integration Tools are not intended to replace a server upgrade as a path to TFS2010 and this scenario should be avoided if possible.

The March 2011 release includes the following features:

  • Out of the box adapter to Team Foundation Server 2010
  • Out of the box adapter to Team Foundation Server 2008
  • Out of the box adapter to Rational ClearCase
  • Out of the box adapter to Rational ClearQuest
  • Out of the box adapter for File system based version control migrations
  • Updated documentation, guidance and case studies (readiness package)
  • Updated User Interface to configure and run integrations
  • Synchronization monitoring tools and reports

Download

 

Visual Studio 2010 Team Foundation Branching guide

Description: The purpose of this project is to build some insightful and practical guidance around branching and merging with Visual Studio Team Foundation Server 2010. The new release focuses on Hands on Labs and includes lots of lessons learnt from the community Q&A.

Download

 

Visual Studio 2010 Team Foundation Server Requirements Management

Description: This Ranger solution addresses the People, Process, and Technology guidance for Requirements Engineering (RE) using Team Foundation Server. The goal of this guidance is to provide formalized Microsoft field experience in the form of recommended procedures and processes, Visual Studio Team System and Team Foundation Server configurations, and skill development references for the Requirements Engineering discipline of your application lifecycle.

Download

 

Microsoft Visual Studio Team Explorer Everywhere 2010

Description: Eclipse plug-in and cross-platform command-line client for Visual Studio 2010 Team Foundation Server.

Download

 

Team Foundation Server Power Tools (March 2011)

Description: A plug-in to Visual Studio, Alerts Explorer provides a graphical user interface that supports flexible subscription of alerts based on check-in, work item change, or build completion.

Download

The Job Interview: Technical questions (Pt. V)

By DimitriC at March 28, 2011 19:16
Filed Under: General, Training, tips & tricks

Here’s one that you might run into when being screened for a technical position: the brain teaser. The point here, usually, is not to see if you can solve a riddle. But more to see how your mind works when an unusual problem arises (see it as creative problem solving). I’ll go over some of the types of questions you may encounter and I’ll also give some references for who like this kind of stuff Smile.

 

The Fermi-question

The answers to these kind of questions are based on estimates and a logical thought-process that accompanies these estimates to derive a valid answer. Often you won’t find the correct answer, but the idea is to get very close. Some of the popular Fermi-questions are: “How many piano tuners are there in the world?” or “How many gas stations are there in the United States of America?”. A bad way to answer these questions is to just give a number and be done with it.

 

On wikipedia you can find a good example of this: “How many piano tuners are there in Chicago?

Next to wikipedia, here is another great resource on the subject: Science Olympics. Here you will also find many examples of Fermi-problems. Some neat ones:

 

- How many golf balls will fit in a suitcase?
- How many hairs are there on a human head?
- If your life earnings were doled out to you by the hour, how much is your time worth per hour?
- People crowd into London until all available open space within the city limits is covered with standing people. How many people would there be?

 

More information about Fermi problems in general can be found on Wikipedia.

 

Creative-thinking question

These are actually just weird questions. Again, keep in mind that the purpose of these questions is to see how you approach a problem that is new to you. For instance: “How are m&m’s made?”, “Without looking at specifications, what is the weight of a Boing 747?” “Why are soda cans produced in that shape?” “Why are manhole covers round?”

 

Some of these questions can be about things that you know. If you know how m&m’s are made, just answer. If you just now looked at you soda can and asked yourself “Why is it made like that?”, you might want to do some thinking. The answer can be simple: They are made like that cause that way they stack easy. The answer can also be scientific: The curves in the can make sure that the build up pressure inside the can doesn’t make the can go boom. If it would be a metal cylinder with the same thickness of steel everywhere, the can probably can’t stand the build up of pressure inside the can.

 

Mathematical questions

 

These questions often have a certain way of looking at a problem to find the solution. Typically, with these questions, when someone gives you the answer you go “aaaahhhhh…of course”. A very famous one here is the riddle that John McClane (played by Bruce Willis) and Zeus Carver (Samuel L Jackson) had to solve in Die Hard: With a Vengeance: You have a jug that can contain 5 liters (let’s call it J5) and a jug that can contain 3 liters (J3). Now, you need to get exactly 4 liters  in the 5-liter-jug. Solution (let’s use water, just like in the movie Smile ):

 

- fill J3 with water

- poor J3 into J5

- fill J3 again with water

- fill J5 to the top (now you added 2 liters, so you have 1 liter in J3)

- empty J5

- fill J5 with the 1 liter from J3

- fill J3

- poor J3 into J5

 

And now J5 contains 4 liters of water.

 

Another one: You have 8 billiard balls. They all have exactly the same weight, except for one. You have a weighing scale like this:

 

 

You need to find the billiard ball that has a different weight with the least amount of weighings.

 

Answer: You can find the billiard ball in two weighings.

 

Put three billiard balls on each side of the scale. If the scale balances to a side, you know in which batch of three the crooked ball is. Now you put one ball of this batch on each side of the scale. If it balances to a side you know which ball is crooked, if it doesn’t, the crooked ball is the remaining one. If in the measurement of 3 versus 3 the scale stays in balance, you just need to measure the remaining two.

 

This can also be done with 9 billiard balls, here when the scale balances to one side in the first weighing, the crooked ball is in the last batch of three. And you still have to just weigh two of them to find the crooked billiard ball.

 

 

 

As you can see, there are many examples of these kinds of questions. You can spend a lot of time surfing the web searching for these questions.

 

There are also several books that cover this subject. Often these books also cover other subjects I talked about in these series (algorithms, programming questions,…)

 

- How would you move Mount Fuji?(William Poundstone)

- Programming Interviews Exposed (John Mongan, Noah Suojanen, Eric Giguère)

- Puzzles for programmers and pros (Dennis Shasha)

- Cracking the coding interview (Gayle Laakmann)

 

…and probably many more Smile

The Job Interview: Technical questions (Pt. II)

By DimitriC at March 09, 2011 19:10
Filed Under: Programming, Training, tips & tricks

Let’s have a look at a binary tree. In my implementation of the binary tree, I use a property to keep track of the fact that the node in question is the root node (= the node where the tree begins), the Parent-property. This refers to the node that has the current node as one of it’s children (or leafs). You can of course browse through your entire tree to find the node that’s not referenced by any other node, but that will probably take a lot of checks, especially if you have a big binary tree. Even when it’s a small binary tree I would use this property. It makes it easier to navigate through the tree.

 

   1: public class BTNode
   2: {
   3:     public BTNode LeftNode { get; set; }
   4:     public BTNode RightNode { get; set; }
   5:     public BTNode Parent { get; set; }
   6:  
   7:     public int value;    
   8:  
   9:     public BTNode(int val)
  10:     {
  11:         this.value = val;
  12:     }
  13:  
  14:     public void AddNode(BTNode newNode)
  15:     {
  16:         newNode.Parent = this;
  17:  
  18:         if (newNode.value >= this.value)
  19:         {
  20:             if (RightNode == null)
  21:             {
  22:                 RightNode = newNode;
  23:             }
  24:             else
  25:             {
  26:                 RightNode.AddNode(newNode);
  27:             }
  28:         }
  29:         else
  30:         {
  31:             if (LeftNode == null)
  32:             {
  33:                 LeftNode = newNode;
  34:             }
  35:             else
  36:             {
  37:                 LeftNode.AddNode(newNode);
  38:             }
  39:         }
  40:     }
  41:  
  42:     public BTNode Search(int srchValue)
  43:     {
  44:         if (srchValue == this.value)
  45:         {
  46:             return this;
  47:         }
  48:  
  49:         if (srchValue >= this.value)
  50:         {
  51:             if (this.RightNode == null)
  52:             {
  53:                 return null;
  54:             }
  55:             else
  56:             {
  57:                 return this.RightNode.Search(srchValue);
  58:             }
  59:         }
  60:         else
  61:         {
  62:             if (this.LeftNode == null)
  63:             {
  64:                 return null;
  65:             }
  66:             else
  67:             {
  68:                 return this.LeftNode.Search(srchValue);
  69:             }
  70:         }
  71:     }
  72:  
  73:     public void Delete()
  74:     {
  75:         //bottom of tree
  76:         if (this.LeftNode == null && this.RightNode == null)
  77:         {
  78:             if (this.Parent.LeftNode.value == this.value)
  79:             {
  80:                 this.Parent.LeftNode = null;
  81:             }
  82:             else
  83:             {
  84:                 this.Parent.RightNode = null;
  85:             }
  86:         }
  87:  
  88:         //Middle of tree - RightNode
  89:         if (this.LeftNode == null && this.RightNode != null)
  90:         {
  91:             if (this.Parent.LeftNode.value == this.value)
  92:             {
  93:                 this.Parent.LeftNode = this.RightNode;
  94:             }
  95:             else
  96:             {
  97:                 this.Parent.RightNode = this.RightNode;
  98:             }
  99:         }
 100:  
 101:         //Middle of tree - LeftNode
 102:         if (this.LeftNode != null && this.RightNode == null)
 103:         {
 104:             if (this.Parent.LeftNode.value == this.value)
 105:             {
 106:                 this.Parent.LeftNode = this.LeftNode;
 107:             }
 108:             else
 109:             {
 110:                 this.Parent.RightNode = this.LeftNode;
 111:             }
 112:         }
 113:  
 114:         if (this.LeftNode != null && this.RightNode != null)
 115:         {
 116:             if (this.Parent == null)
 117:             {
 118:                 throw new ApplicationException("You can not delete the root node!");
 119:             }
 120:  
 121:             if (this.Parent.LeftNode.value == this.value)
 122:             {
 123:                 this.Parent.LeftNode = this.LeftNode;
 124:                 this.LeftNode.RightNode = this.RightNode;
 125:             }
 126:             else
 127:             {
 128:                 this.Parent.RightNode = this.RightNode;
 129:                 this.RightNode.LeftNode = this.LeftNode;
 130:             }
 131:         }
 132:     }

 

To use it, you instantiate a node and assign new BTNodes to the leaves. Wherever you are in the tree-structure, you’ll find it easy to search for nodes. Keep in mind that the AddNode and Delete only reflect on the current node.

The known bug with the WCF Service Configuration Editor

By DimitriC at January 21, 2011 22:43
Filed Under: Programming, Visual Studio, tips & tricks, tools & Utilities, WCF

In both Visual Studio 2008 and 2010 there is a bug when you try to use the WCF Service Configuration Editor. The editor should be reachable through the Tools-menu or by right clicking a configuration file (web.config / app.config). This appears to be a known bug. It’s not blocking, but it’s easier to access the editor directly from the configuration file (then the file is immediately loaded in the editor). 

When you just started Visual Studio, and right-click a configuration file, the editor is not visible as an option:

 

image

 

 

Now open the editor from the tools menu (Tools –> WCF Service Configuration Editor):

 

image

 

Now the editor will open. You can close it immediately and go back to the configuration file. When you right-click it now, you will see that the option to open the editor is available:

 

image

Get application version, build and build date

By DimitriC at April 13, 2010 15:09
Filed Under: Programming, tips & tricks

In one of my console applications I wanted to show the assembly version, build and build date in the console window.

 

For getting the assembly version and build, the System-namespace has a Version-object which has properties like MajorVersion, MinorVersion and Build that you can use. When you call the ToString()-method on this object, you will get the full version information.

   1: Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

Now you can use the properties to build your text message:

   1: string versionMsg = "Version: " + version.ToString() + " - Build: " + version.Build + ";

 

The problem is that the Build-property remains 0. To solve this, you must use wildcards in the AssemblyInfo.cs file. This will allow for a build-number to be generated:

   1: [assembly: AssemblyVersion("1.0.*")]

 

If you re-run the program, a build number will be visible.

 

Now getting the build date from all of this is tricky too. The Version.Build consists the number of days since January 1, 2000. The Version.Revision property counts the seconds since midnight which you have to multiply by 2 to get the original:

   1: DateTime buildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * version.Build + // days since January 1, 2000 
   2:     TimeSpan.TicksPerSecond * 2 * version.Revision)); // seconds since midnight, today

 

Now you have all the information you need to build the final versionMsg:

   1: string versionMsg = "Version: " + version.ToString() + " - Build: " + version.Build + " - Build Date: " + buildDateTime.ToString();